Terraform v0.10.7
The real-world example is a bit more complicated, but I believe the bug should be reproducible with just this:
output "foo" {
value = map("foo.bar.", "baz")
}
terraform {
backend "s3" {
bucket = "my-bucket"
key = "foo/terraform.tfstate"
region = "us-east-1"
}
}
That is, I have a module foo that has a simple map as an output variable, and stores its state in an S3 bucket.
I then have another module that tries to read that state using terraform_remote_state:
data "terraform_remote_state" "foo" {
backend = "s3"
config {
region = "us-east-1"
bucket = "my-bucket"
key = "foo/terraform.tfstate"
}
}
output "foo" {
value = "${data.terraform_remote_state.foo.foo}"
}
I expected to see:
foo = {
"foo.bar.": "baz"
}
I see:
foo = {
foo = map[bar:map[:baz]]
}
It's multiple maps nested with each other! And the dots are missing.
On each module, run:
terraform initterraform applyPerhaps similar to #16166?
Hi @brikis98! Sorry for this strange behavior.
It's known that right now, in several places, Terraform mis-handles names that contain periods due to the way data is serialized internally.
This is a bug, but it's unfortunately one particular manifestation of quite a fundamental architectural limitation in Terraform today that results from some legacy code that existed before Terraform had support for lists and maps.
There is an effort underway right now to resolve the broader problem here, but it's a multi-step process that we need to take incrementally. The first step for this will appear soon: a next-generation version of HCL that has better support for lists and maps _within the language_ and which provides suitable representations of these to allow them to pass without misinterpretation. Later work spread these new representations throughout Terraform core, including in outputs, thus ensuring that misinterpretations like this no longer occur.
For now, unfortunately, the best we can do is to advise against including periods in map keys until this issue is resolved.
Understood, thanks for the explanation. The data were were storing in the map contains domain names (e.g., foo.bar.com), so not much we can do about dots. Perhaps use replace to swap them out for double underscores in the output and then replace again to switch it back when reading the data... But feels quite messy.
Hi @brikis98!
It turns out that this was actually a duplicate of another issue #11534, which I recently closed after verifying the fix against v0.12.0-alpha2. Therefore I'm going to close this one out too. The fix will be included in the forthcoming v0.12.0 final release.
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 @brikis98!
It turns out that this was actually a duplicate of another issue #11534, which I recently closed after verifying the fix against v0.12.0-alpha2. Therefore I'm going to close this one out too. The fix will be included in the forthcoming v0.12.0 final release.