هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
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-allplan|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
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 10
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1The folder layout
tree live live/ ├── terragrunt.hcl ├── prod │ ├── network/terragrunt.hcl │ └── aks/terragrunt.hcl └── dev ├── network/terragrunt.hcl └── aks/terragrunt.hcl2The 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" } }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 }4Plan one module
cd live/prod/aks terragrunt plan5Plan a whole environment
cd live/prod terragrunt run-all plan6Apply everything in CI
terragrunt run-all apply --terragrunt-non-interactive7Use OpenTofu
TERRAGRUNT_TFPATH=tofu terragrunt plan8See the order
terragrunt graph-dependencies9Test a local module change
terragrunt plan --terragrunt-source ../../../../tf-modules//aks10Format all files
terragrunt hclfmt
لا يوجد شيء يطابق هذا الفلتر.
انتبه
run-all applyandrun-all destroychange 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.
رموز الخروج
0 | OK. |
1 | Error. |