Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

terragrunt

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

Niveau
DevOps-tool
Groep
Infrastructuur als code en cloud
Root nodig
Nee
Pakket
terragrunt

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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).

Zo schrijf je het

terragrunt COMMAND [OPTIONS]
terragrunt run-all COMMAND

Belangrijkste delen

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.

Opties 6

Meest gebruikt

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.

Voorbeelden 10

$ als gewone gebruiker# als root (of met 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

Let op

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

Bestanden

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

Exitcodes

0OK.
1Error.