Closed sheldonhull closed 3 years ago
Hi there!
You need to start debugging from an internal directory and try to get it to work first:
cd terragrunt/staging/eu-central-1/vpc
terragrunt init
terragrunt apply
Then you can go one level up and try to run terragrunt apply-all
.
I don't think I have simple+working Terragrunt code in the open-source where common.tfvars
is used but maybe you can see how I write it in other places, too:
https://github.com/antonbabenko/modules.tf-demo
https://github.com/terraform-aws-modules/meta
In general, the questions related to the terragrunt are better to ask on the official repository as there are more users who may help you.
For future reference I realized I misread the commands.
I needed terragrunt run-all plan
for this to work correctly. Now my output is correct. I didn't realize I was nesting 2 layers of subcommands.
The other bit someone in sweetops slack community mentioned was deprecation of using tfvars. Instead they said to use:
inputs = merge(
# Configure Terragrunt to use common vars encoded as yaml to help you keep often-repeated variables (e.g., account ID)
# DRY. We use yamldecode to merge the maps into the inputs, as opposed to using varfiles due to a restriction in
# Terraform >=0.12 that all vars must be defined as variable blocks in modules. Terragrunt inputs are not affected by
# this restriction.
yamldecode(
file("${find_in_parent_folders("region.yaml", "empty.yaml")}"),
),
yamldecode(
file("${find_in_parent_folders("env.yaml", "empty.yaml")}"),
),
due to the changes in the behavior that block the tfvars from being pulled in correctly, while yaml works fine in loading into TF
inputs.
I'm still having a problem with it loading a parent file from a child, but will work from your example and see if I can get this to work then.
It worked this time from parent directory! Woot Woot. :tada:
Thanks again for the help.
Good that it works!
Yes, yamldecode
is an option if you want to deal with YAML or have a lot of variables.
I usually prefer to deal with hcl files using read_terragrunt_config()
as I have here - https://github.com/terraform-aws-modules/meta/blob/master/github/repositories/terraform-aws-modules/terraform-aws-appsync/terragrunt.hcl#L10
Much better. Prefer to keep it terraform focused and not yaml. Will give that a try
That worked great and was much more intuitive as well. Thanks again as that helped unblocked me!
You are welcome.
Maybe I should have one more episode about Terragrunt during Your Weekly Dose of Terraform. Who knows :)
This file uses commands to load
common.tfvars
andregional.tfvars
However, it seems to have a problem loading this common.tfvars in when it runs, saying it can't find common.tfvars.
I just tried navigating into the region level directory under the "parent" terragrunt.hcl file. It errored out and no detail on error, just this
It also generated a backend file in the "parent" directory that has the common variables, but is not the individual region's section.
When I copied the debug command output and run the command below it plans fine.
This is a bit confusing as new terragrunt user. I'm not seeing the native terraform commands exposed easily to know what happened, it's just outputting the terraform help content.
The error doesn't even show the actual terraform init/plan command, just this:
Directory Structure