Terraform v0.12.0
terraform {
required_version = ">= 0.12"
}
variable "name_test" {
default = "hello"
}
locals {
hash = {
(var.name_test) = "world",
}
}
https://gist.github.com/mavin/4e796c4d43b233ce75f2a8cfc9557141
The given config should be valid, according to the docs; if it isn't then there should be a more helpful error message.
An error is thrown that recommends changes that are already present in the config.
$ terraform validate
Error: Ambiguous attribute key
on vars.tf line 11, in locals:
11: (var.name_test) = "world",
If this expression is intended to be a reference, wrap it in parentheses. If
it's instead intended as a literal name containing periods, wrap it in quotes
to create a string literal.
terraform initterraform validateAll this happens with a fresh environment and a new config.
Thanks for reporting this, @mavin!
This is indeed a bug, probably in the underlying HCL library. :confounded: We'll investigate it.
In the mean time, you may be able to get this to work by using the interpolation syntax as an alternative way to disambiguate it:
"${var.name_test}" = "world",
:taco:
Is this still a bug or we need to refactor our code to comply with the new syntax? I'm using v0.11.13.
I am trying to upgrade our (huge) repo from V0.11.14 to 0.12.14. It does not look viable to manually change to interpolation syntax everywhere. Is there a better way to get it working until we fix this bug?
@apparentlymart Given that 0.13 is coming soon, does it make sense to assume that this bug won't be fixed in 0.12?
This bug was actually fixed in 0.12.10, as part of this PR updating the HCL version. It continues to be fixed in 0.13.
$ cat main.tf
terraform {
required_version = ">= 0.12"
}
variable "name_test" {
default = "hello"
}
locals {
hash = {
(var.name_test) = "world",
}
}
$ terraform-0.12.9 validate
Error: Ambiguous attribute key
on main.tf line 11, in locals:
11: (var.name_test) = "world",
If this expression is intended to be a reference, wrap it in parentheses. If
it's instead intended as a literal name containing periods, wrap it in quotes
to create a string literal.
$ terraform-0.12.10 validate
Success! The configuration is valid.
$ terraform-0.12.28 validate
Success! The configuration is valid.
$ terraform-0.13.0-beta2 validate
Success! The configuration is valid.
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
Is this still a bug or we need to refactor our code to comply with the new syntax? I'm using v0.11.13.