Imagine you have the following folder structure:
infra-live
â”” global.tfvars
â”” stage
â”” terraform.tfvars
The stage/terraform.tfvars has the following contents:
terragrunt = {
terraform {
source = "git::[email protected]:foo/bar.git//frontend-app?ref=v0.0.3"
}
extra_arguments "global" {
arguments = [
"-var-file=terraform.tfvars",
"-var-file=../global.tfvars"
]
}
}
When you run terragrunt apply in stage, it will fail, because it will download the Terraform code into a temporary folder, switch to that folder, and then try to use the relative path to global.tfvars. Since global.tfvars is in the infra-live folder and not the temp folder, it won't find it.
Ideas on possible fixes:
Explicitly parse extra_arguments for -var-file arguments and automatically copy those into the proper folder structure in the temporary folder. This sounds like it would be very messy.
Instead of downloading code into a temporary folder, download it into the current folder, run Terraform, and then clean up. Again, this sounds like it would be very messy.
Add a new helper similar to ${path.module}. For example:
arguments = [
"-var-file=${path.module}/terraform.tfvars",
"-var-file=${path.module}/../global.tfvars"
]
Terragrunt would automatically fill in the path of the original working directory, so those relative paths would become absolute paths.
The third option seems like the proper solution and it should be pretty easy to implement. Anyone up for a PR?
As a workaround you can symlink ../global.tfvars into your stage directory and reference the symlink file into the extra_argument block. This way you can reuse the same global.tfvars everywhere without code duplication.
example:
infra-live
â”” global.tfvars
â”” stage
â”” terraform.tfvars
â”” global.tfvars (symlink -> ../global.tfvars)
stage/terraform.tfvars:
terragrunt = {
terraform {
source = "git::[email protected]:foo/bar.git//frontend-app?ref=v0.0.3"
}
extra_arguments "global" {
arguments = [
"-var-file=terraform.tfvars",
"-var-file=global.tfvars"
]
}
}
Fix here: https://github.com/gruntwork-io/terragrunt/pull/168. Feedback welcome!
Whoops, meant to hit comment, but hit close. Reopened this one until #168 is merged :)
Fixed by #170.
Most helpful comment
Ideas on possible fixes:
Explicitly parse
extra_argumentsfor-var-filearguments and automatically copy those into the proper folder structure in the temporary folder. This sounds like it would be very messy.Instead of downloading code into a temporary folder, download it into the current folder, run Terraform, and then clean up. Again, this sounds like it would be very messy.
Add a new helper similar to
${path.module}. For example:Terragrunt would automatically fill in the path of the original working directory, so those relative paths would become absolute paths.
The third option seems like the proper solution and it should be pretty easy to implement. Anyone up for a PR?