Running terraform output for an output whose value has a nested map returns a list of one map rather than just a map.
0.10.8
0.11.1
output "example" {
value = {
"some_key" = {
"some_nested_key" = "some_value"
}
}
}
The nested map is preserved
{
"example": {
"sensitive": false,
"type": "map",
"value": {
"some_key": {
"some_nested_key": "some_value"
}
}
}
}
A list is inserted
{
"example": {
"sensitive": false,
"type": "map",
"value": {
"some_key": [
{
"some_nested_key": "some_value"
}
]
}
}
}
Note that if you nest deeper, another list is inserted where there should be just a map.
E.g.
{
"example": {
"sensitive": false,
"type": "map",
"value": {
"some_key": [
{
"some_nested_key": [
{
"some_value": "more_nested"
}
]
}
]
}
}
}
rm -rf .terraform/ && rm -f terraform.tfstate && terraform init && terraform plan && terraform apply && terraform output -json
Hi @stefano-m! Sorry for this weird behavior.
Unfortunately this is a result of a limitation of Terraform's current configuration language parser, which has some ambiguity in how it deals with { ... } sequences that result from their use in named nested blocks.
However, the better news is that we're already in the process of integrating an improved parser that doesn't have this problem, and so a fix for this is in progress. In the mean time, I think you could work around this by using the map function to produce your map, rather than the brace syntax:
output "example" {
value = "${map("some_key", map("some_nested_key", "some_value"))}"
}
I understand that this syntax gets unwieldy quickly when the map structure is complex, and so that's why we made sure to make the more convenient {-based syntax work properly in the new parser.
Sorry again for the weirdness here. Hopefully it's not too much longer before we have the new parser integrated.
Hi again, @stefano-m!
I'm pleased to report that this is now fixed in master, ready for the forthcoming v0.12.0 release. I verified this using the v0.12.0-alpha1 prerelease build, using the example configuration you gave in your original comment:
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
example = {
"some_key" = {
"some_nested_key" = "some_value"
}
}
Since a fix is merged, I'm going to close this out now. Thanks for reporting this, and thanks for your patience while we did the groundwork to get this working.
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
Hi again, @stefano-m!
I'm pleased to report that this is now fixed in master, ready for the forthcoming v0.12.0 release. I verified this using the v0.12.0-alpha1 prerelease build, using the example configuration you gave in your original comment:
Since a fix is merged, I'm going to close this out now. Thanks for reporting this, and thanks for your patience while we did the groundwork to get this working.