627 shaares
Depuis Terragrunt v0.10.0, la configuration S3 et DynamoDB permettant de gérer les states et lock Terraform se trouve dans terraform.tfvars
au lieu de .terragrunt
.
Exemple de configuration avec un repo de configuration et un repos module:
- arborescence:
* terraform-configuration-repo
|- dev
|- test
|- prod
|- application
| |- terraform.tfvars
| |- main.tfvars (symlink -> ../main.tfvars)
|- terraform.tfvars
|- main.tfvars
* terraform-module-application-repo
|- main.tf
|- vars.tf
|- ...
- terragrunt configuration spécifique to
application
:
# terraform-configuration/prod/application/terraform.tfvars
terragrunt = {
terraform {
source = "git@github.com:myuser/tf-modules-application-repo.git///ref=1.0.0"
extra_arguments "main" {
arguments = [
"-var-file=main.tfvars",
"-var-file=terraform.tfvars"
]
commands = [
"plan",
"apply"
]
}
}
include {
path = "${find_in_parent_folders()}"
}
}
# variables specifics to application module
var1 = "XXX"
var2 = "YYY"
# var3 can override var3 from main.tfvars environment variables
var3 = "BBB"
...
- terragrunt configuration spécifique to
prod
environnement:
# terraform-configuration/prod/terraform.tfvars
terragrunt = {
# Configure Terragrunt to use DynamoDB for locking
lock = {
backend = "dynamodb"
config {
state_file_id = "prod"
}
}
# Configure Terragrunt to automatically store tfstate files in an S3 bucket
remote_state = {
backend = "s3"
config {
encrypt = "true"
bucket = "s3-terraform-states"
key = "prod/${path_relative_to_include()}/terraform.tfstate"
}
}
}
- global variables for
prod
environment:
# terraform-configuration/prod/main.tfvars
# variables specifics to prod environment
var3 = "ZZZ"
var4 = "AAA"