I am working on a prototype at work for using Terraform/Terragrunt with Azure. As I am still testing stuff, I am just using the local
backend for my deployments.
Everything works as I want so far. However I am running into my first big hurdle that has me stupefied a bit.
Layout at the moment:
development/
bastion/
terragrunt.hcl
infrastructure/
terragrunt.hcl
environment.tfvars
modules/
bastion/
main.tf
variables.tf
infrastructure/
main.tf
output.tf
variables.tf
common.tfvars
terragrunt.hcl
The top-level terragrunt.hcl has:
terraform {
extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars()
arguments = [
"-var-file=${get_terragrunt_dir()}/../../common.tfvars",
"-var-file=${get_terragrunt_dir()}/../environment.tfvars"
]
}
}
remote_state {
backend = "local"
config = {
path = "${path_relative_to_include()}/terraform.tfstate"
}
}
I use common.tfvars
and environment.tfvars
to pass along some required variables for my future DTAP setup, region, and so on.
I have a main infrastructure stack/module. From this I output a bunch of things via outputs.tf
inside the module. Within one of my other stacks I add a dependency on this infrastructure stack via the terragrunt.hcl
of the former with:
include {
path = find_in_parent_folders()
}
dependency "infrastructure" {
config_path = "../infrastructure"
mock_outputs = {
management_subnet = "some-id"
}
mock_outputs_allowed_terraform_commands = ["validate"]
}
inputs = {
management_subnet = dependency.infrastructure.outputs.management_subnet
}
A terragrunt validate
succeeds. Deployment of the infrastructure stack creates my outputs, including the one mentioned above. However, when I want to use the output in my dependent stack I get the message that it did no detect any outputs: /work/development/infrastructure/terragrunt.hcl is a dependency of /work/infrastructure/development/bastion/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.
I think this has to do because Terragrunt is evaluating the tfstate of infrastructure in its local .terragrunt-cache
hierarchy (of the bastion subdirectory). That file has, indeed, no outputs. The file in infrastructure
has outputs
defined. Can I easily make this work or will I need to mess around with terraform_remote_state
? Any guidance welcome.