-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpolation issue for multi-dimensonal/nested lists #11036
Comments
Hi @vancluever, You're right that this is a HIL issue rather than directly a Terraform issue, and indeed I've been working on it over in hashicorp/hil#42 though I stalled a bit over the holidays. I don't remember there being a Terraform issue about this yet, so I'm going to leave this here to represent the need to update the vendored HIL and make the required changes to Terraform's interpolation functions once that issue is resolved. |
The same issue (but, as far as I could see, no workaround) occurs when trying to do the invers (having a map inside a list) example:
There's no way to actually get the vars, only the entire object (one of my attempts, errors out)
|
Try: |
For nested maps, for example, for configure it based on the Terraform workspace, you can use: variable "nested_map_name" {
default = {
default = {
value1 = 10
value2 = false
}
staging = {
value1 = 20
value2 = false
}
production = {
value1 = 50
value2 = true
}
}
}
resource "resource_where_use_nested_map" "resource_name" {
resouce_param1 = "${lookup(var.nested_map_name[terraform.workspace], "value1")}"
resouce_param2 = "${lookup(var.nested_map_name[terraform.workspace], "value2")}"
} (Remember that you don't have to add interpolation on Terraform variables) |
I've just tried a variant of the original non-working example on Terraform v0.12.0-alpha1: variable "public_subnet_addresses" {
type = "map"
default = {
production = ["10.0.0.0/25", "10.0.0.128/25"]
staging = ["10.0.1.0/25", "10.0.1.128/25"]
}
}
output "element_from_list_from_map" {
value = var.public_subnet_addresses["production"][0]
} And now it works as expected!
In the end this has been resolved not by a change in HIL but by moving Terraform over to HCL 2.0, which incorporates HIL-like expression functionality but has full support for chaining attribute and index syntax after any expression. Thanks for reporting this! |
this blog is helpful, it gives full solution with real example you can reference. https://salekseev.com/posts/nested-maps-in-terraform-variables/ |
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. |
Possibly HIL/HCL related, might be known, couldn't find an issue in my <5min sanity check. Logging to track.
EDIT: Related: #8047
The Variable
Good
Gives:
Bad
Gives:
The text was updated successfully, but these errors were encountered: