[ci skip] phase 3: switch terragrunt to load config.tfvars + SOPS secrets

terragrunt.hcl now loads:
- config.tfvars (required, plaintext)
- terraform.tfvars (optional, git-crypt — backward compat)
- secrets.auto.tfvars.json (optional, SOPS-decrypted)

before_hook checks that at least one secrets source exists.
Use `scripts/tg` wrapper for SOPS-based workflow.
Old terraform.tfvars kept for reference and backward compatibility.
This commit is contained in:
Viktor Barzin 2026-03-07 14:16:28 +00:00
parent 22267fe386
commit 154f8ff0c1
No known key found for this signature in database
GPG key ID: 0EB088298288D958

View file

@ -13,13 +13,18 @@ remote_state {
} }
} }
# Load terraform.tfvars for all stacks. # Load config.tfvars (plaintext) + secrets.auto.tfvars.json (SOPS-decrypted).
# Variables not declared by a stack are silently ignored (Terraform 1.x behavior). # Run `scripts/tg` instead of raw `terragrunt` it decrypts secrets first.
# Falls back to terraform.tfvars if it exists (migration compatibility).
terraform { terraform {
extra_arguments "common_vars" { extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars() commands = get_terraform_commands_that_need_vars()
required_var_files = [ required_var_files = [
"${get_repo_root()}/terraform.tfvars" "${get_repo_root()}/config.tfvars"
]
optional_var_files = [
"${get_repo_root()}/terraform.tfvars",
"${get_repo_root()}/secrets.auto.tfvars.json"
] ]
} }
@ -29,6 +34,12 @@ terraform {
"-var", "kube_config_path=${get_repo_root()}/config" "-var", "kube_config_path=${get_repo_root()}/config"
] ]
} }
# Safety: fail if neither secrets source exists
before_hook "check_secrets" {
commands = ["apply", "plan", "destroy"]
execute = ["sh", "-c", "test -f ${get_repo_root()}/secrets.auto.tfvars.json || test -f ${get_repo_root()}/terraform.tfvars || (echo 'ERROR: No secrets file found. Run scripts/tg instead of terragrunt directly.' && exit 1)"]
}
} }
# Generate kubernetes + helm providers for K8s stacks. # Generate kubernetes + helm providers for K8s stacks.