Access map output value

Hi,
I’m trying to access output value from the zones route53 module.
This is the module:

the output from the module is like that:
route53_zone_name = {
in.po.example.com” = “in.po.example.com
}

I need the domain name “in.po.example.com” in order to create records

I tried the following:
dependency “dns_zones” {
config_path = “…/zones”
}

inputs = {
private_zone = true
zone_name = dependency.dns_zones.outputs.route53_zone_name.in.po.example.com
records = [
{
name = “yn-test”
type = “A”
ttl = 3600
records = “1.1.1.1”
}
]
}
)

do you know how can I get the domain from this output?

if the dependency output is a map, and you need a specific value from that map, and you know the key of the value you’re trying to get, then you can use a lookup:

dependency “dns_zones” {
    config_path = “…/zones”
}

inputs = {
private_zone = true
zone_name   = lookup(dependency.dns_zones.outputs.route53_zone_name, “in.po.example.com”, "ERR")
...

this module output doesn’t make a lot of sense to me though… if the value is the same as the key, then what’s the point of the map? why not just output a string instead of a map, like (in terraform):

output "route53_zone_name" {
    value = "in.po.example.com"
}

then get the value like zone_name = dependency.dns_zones.outputs.route53_zone_name in the inputs section and save urself the hassle of the lookup? it sounds like maybe either this is just an example and in your real code the key doesn’t match the value, or maybe this map is gonna have multiple entries in it where the key might not necessarily match the value (if there might be multiple entries in there but the key would always match the value, I’d use a list instead). in either case, it might make sense to instead pass the entire map as an input to the terraform module, then do the lookup in terraform instead (or if you have multiple values in this list and need to create multiple resources, you can iterate over the keypairs in the terraform module with for_each to iteratively create your resources without having to explicitly declare each one), which would just look like zone_name = dependency.dns_zones.outputs.route53_zone_name, then you can do the same kind of lookup but in terraform instead (the lookup function in terragrunt is inherited from terraform so the syntax is the same except you’d be doing the lookup against var.route53_zone_name instead)

1 Like

This is a public module of AWS and I wanted to understand how can I work with it without doing changes in the module.
I think I can use a different key for each domain (not the domain name) and then it will make more sense.
This lookup example help me understand how to work with this output
Thanks