Since I don’t have the name of module, in used way like module.vpc I’m not able to get the output of my nested block, as well I can not do simple:
output "vpc_id" {
value = module.vpc.id
}
So, can someone help me to get, output of nested block? At the end I would like to pass the output to inputs block, so my other network related resources could use the vpc_id, something like this:
As far as I know, you cannot pull values from a nested source. The common pattern is to pass-through outputs from a deeper module, to the outer module. Here’s what I think you’re trying to do. Please let me know if I’m misunderstanding.
And if you’re saying, that I can not in any of ways pull the output of block (block is above), maybe there’re some workarounds? Of course with out changing directory and file hierarchy?
I think what you’re asking must be possible, but I am missing the picture. Could you share your code, redacting anything private/sensitive, so that I can see exactly what you’re talking about? Please include as much as you can.
The child terragrunt.hcl’s also seem like the right place to put the inputs block for the vpc_id.
Assuming a set up like this, you can use the dependency block in your child terragrunt.hcl files. In your child terragrunt.hcls, it should be clear where the VPC module exists relative to that path. You set that as the config_path in the dependency block, and the input can use that dependency.my_vpc.outputs.vpc_id as the input. Like so:
dependency "my_vpc" { # whatever label you use here will be part of the dependency path below
config_path = "../vpc"
}
inputs = {
vpc_id = dependency.my_vpc.outputs.vpc_id
}
Read about this here: passing outputs between modules. Now Terragrunt knows it must deploy the VPC module first before the modules that depend on that output. And you don’t have to worry too much about the relative pathing from the root terragrunt.hcl file because the inputs are being passed at the child level.