The global variable region has two values: apac, amr and eu. Now how do I call this region_lookup function?
I have tried: region_lookup.${var.region}.service_1 and region_lookup.[var.region][service_1] but neither worked.
Thanks for replying to me. I missed “local.” in the original post.
When I tried: service=${local.region_lookup.[var.region][“service_1”]}, the TF format tool gives me “An attribute name is required after a dot.” error.
Closet I could get was something like: service=${local.region_lookup[var.region][service_1]} though this gives me the “A reference to a resource type must be followed by at least one attribute access, specifying the resource name.” error…
You don’t have a function, because the Terraform language doesn’t support the concept of functions - what you have is a local variable containing some nested objects.
Both of these have an incorrect ${ } enclosing the expression, as @macmiranda pointed out.
Additionally, the first contains an incorrect extra . whilst the second is missing some necessary quotes.
Taking a little from one, a little from the other, a correct version would be:
service = local.region_lookup[var.region]["service_1"]
or you could also write it as
service = local.region_lookup[var.region].service_1