After a couple of months not dealing with infrastructure changes, I tried to load up our terragrunt files on a new machine and ran into a couple of errors, that I couldn't find a solution to.
Basically it seems, that the terraform.tfvars
file (or any *.auto.tfvars
file for that matter) get's ignored by terraform, when there's a -var
or -var-file
option present.
We're using a hierarchical terragrunt config to have different credential configuration for different environments, that's why there's an account.tfvars
file, that contains all the data.
Everything has worked as late as August this year, so maybe there was a change that I didn't spot in the changelog?
module specific terraform.tfvars
:
terragrunt = {
include {
path = "${find_in_parent_folders()}"
}
terraform {
source = "../../../modules//cockpit"
}
}
bucket_prefix = "cockpit-"
domain_name = "cockpit.donutapp.io"
parent terraform.tfvars
:
terragrunt = {
remote_state {
backend = "s3"
config {
encrypt = true
bucket = "my-${get_aws_account_id()}-tfstate"
key = "production/${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
}
}
terraform {
extra_arguments "bucket" {
commands = ["${get_terraform_commands_that_need_vars()}"]
optional_var_files = [
"${get_tfvars_dir()}/${find_in_parent_folders("account.tfvars", "ignore")}",
]
arguments = [
"-var",
"terraform_bucket=my-${get_aws_account_id()}-tfstate",
]
}
extra_arguments "disable_input" {
commands = ["${get_terraform_commands_that_need_input()}"]
arguments = ["-input=false"]
}
}
}
executed command by terragrunt:
terraform plan -var terraform_bucket=my-accountid-tfstate \
-var-file=some-path/../account.tfvars \
-input=false
When I add -var-file=terraform.tfvars
as an argument to the terraform plan
command in the .terragrunt-cache
folder, it does work, so it just doesn't get loaded automatically.
Any thoughts?