الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

terragrunt

A thin wrapper around Terraform/OpenTofu that keeps many environments DRY: one backend config, shared inputs, and run-all over many modules.

المستوى
أداة DevOps
المجموعة
البنية التحتية ككود والسحابة
يحتاج root
لا
الحزمة
terragrunt

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

With many environments (dev, staging, prod) and many parts (network, cluster, database) plain Terraform gets repetitive: the same backend block and variables again and again. terragrunt puts the shared parts in a root terragrunt.hcl; every folder only says which module to use and its inputs.

terragrunt run-all plan runs plan in every folder in the right order (dependencies first).

طريقة الكتابة

terragrunt COMMAND [OPTIONS]
terragrunt run-all COMMAND

الأجزاء الرئيسية

Commands

plan / apply / destroy
Like Terraform, for this folder.
run-all plan|apply
In all folders below, in dependency order.
init
Init with the generated backend.
output / validate / fmt
Like Terraform.
hclfmt
Format terragrunt.hcl files.
graph-dependencies
Show the order of modules.
render-json
Show the final config.

الخيارات 6

الأكثر استخدامًا

Options

--terragrunt-non-interactive
No questions (CI).
--terragrunt-working-dir DIR
Run in another folder.
--terragrunt-include-dir GLOB
Only these folders in run-all.
--terragrunt-parallelism N
Limit parallel modules.
--terragrunt-source PATH
Use a local module copy (development).
TERRAGRUNT_TFPATH=tofu
Use OpenTofu instead of Terraform.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1The folder layout

    tree live
    live/
    ├── terragrunt.hcl
    ├── prod
    │   ├── network/terragrunt.hcl
    │   └── aks/terragrunt.hcl
    └── dev
        ├── network/terragrunt.hcl
        └── aks/terragrunt.hcl
  2. 2The root file: one backend for all

    cat live/terragrunt.hcl
    remote_state {
      backend = "azurerm"
      generate = { path = "backend.tf", if_exists = "overwrite" }
      config = {
        resource_group_name  = "rg-tfstate"
        storage_account_name = "sttfstateacme"
        container_name       = "tfstate"
        key                  = "${path_relative_to_include()}/terraform.tfstate"
      }
    }
  3. 3One module with its inputs

    cat live/prod/aks/terragrunt.hcl
    include "root" { path = find_in_parent_folders() }
    terraform { source = "git::https://github.com/acme/tf-modules.git//aks?ref=v2.1.0" }
    dependency "network" { config_path = "../network" }
    inputs = { subnet_id = dependency.network.outputs.subnet_id, node_count = 3 }
  4. 4Plan one module

    cd live/prod/aks
    terragrunt plan
  5. 5Plan a whole environment

    cd live/prod
    terragrunt run-all plan
  6. 6Apply everything in CI

    terragrunt run-all apply --terragrunt-non-interactive
  7. 7Use OpenTofu

    TERRAGRUNT_TFPATH=tofu terragrunt plan
  8. 8See the order

    terragrunt graph-dependencies
  9. 9Test a local module change

    terragrunt plan --terragrunt-source ../../../../tf-modules//aks
  10. 10Format all files

    terragrunt hclfmt

انتبه

  • run-all apply and run-all destroy change many modules at once — review the plans first.
  • Pin module sources with ?ref=TAG.

الملفات

terragrunt.hcl
Config of a folder (and the root).
.terragrunt-cache/
Downloaded code; add to .gitignore.

رموز الخروج

0OK.
1Error.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man terragrunt