Is it possible to get variable interpolation in tag keys?
Something like this:
tags {
"${var.global_tag_key}" = "${var.global_tag_value}"
}
When I try it now, it just seems to set the tag key to the literal string ${var.global_tag_key}, instead of of interpolating it.
Is this intended behavior? If so, would you accept a PR that changes this behavior to allow interpolation inside tag keys?
Hi @saulshanabrook -
I can see this being useful. it might be nontrivial to implement, but you're welcome to take a stab at a PR if you like!
@phinze OK makes sense, I will take a look
Would love to see this working!
Or something similar to the way auto scaling group handles tag would be great.
Hi @saulshanabrook! Thanks for opening this and sorry for the long silence.
This seems to be the same as what was suggested in #2042, which I just closed with a comment explaining the current suggested way to achieve this.
To add some more color here, since you were asking about whether we'd accept a PR for interpolation inside keys in particular: in general we prefer the overall configuration structure to be "static", since this enables us to catch a variety of interesting errors during a validation pass that can happen before any interpolations are resolved. However, attributes that are defined as being maps are a special case because their keys truly are dynamic, and can (as my comment in the other issue shows) be set dynamically via the interpolation language.
So it's likely that in future we will make some improvements to HCL/HIL syntaxes to make such a construct more natural, but we may approach it in a different way than simply allowing interpolations generally in keys so that structured configuration elements (as opposed to maps) can still be reliably validated.
I'm going to close this out because the use-case is now served, albeit in a sub-optimal way, using the map function. When we make improvements to the language in future they will likely be more holistic changes, which will have their own issues/PRs as appropriate. Thanks again!
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Would love to see this working!
Or something similar to the way auto scaling group handles tag would be great.