The new locals block in v0.10.3 is a much-needed feature, but it only works if there is a single main.tf file in the module.
With a single main.tf file:
terraform {
required_version = "~> 0.10.3"
}
provider "aws" {
version = "~> 0.1.4"
region = "us-east-1"
}
locals {
dashboard_body = {
widgets = []
}
}
resource "aws_cloudwatch_dashboard" "hi" {
dashboard_name = "Hi"
dashboard_body = "${jsonencode(local.dashboard_body)}"
}
And terraform validate returns with no error.
All you have to do is create another empty .tf file in the same directory:
touch other.tf
And now:
terraform validate
* aws_cloudwatch_dashboard.hi: 1 error(s) occurred:
* aws_cloudwatch_dashboard.hi: local.dashboard_body: no local value of this name has been declared
Similarly, you can put the terraform and provider blocks in main.tf and the locals and resource blocks in aws.tf, and you get the same validation error.
main.tf file listed abovetouch other.tfterraform initterraform validateThis is happening to me too.
Thanks for reporting this, @austinbyers! This seems like a bug snuck in to the validation code. I'll take a look.
Looks like I managed to lose some stuff during commit or a later rebase that broke the multi-file merging behavior and all of our tests were only single files. :confounded:
Sorry about that, all. I'm working on getting the merging code back and then fleshing out some more tests to verify the merging behavior.
Yeah, I just hit this too. I'm using locals in a separate shared-data module (so multiple other modules can use the same data via remote state) but it only works if I put all the code in one file.
Would be good to release 0.10.4 soon with this fix. Locals are broken for many without.
Hi all!
Sorry for the delay in getting this out; we had to hold for another fix to be included in that release. It was included in today's 0.10.4 release.
I'm hitting this again with Terraform v0.11.8 I think
@fzakaria although you may be seeing similar symptoms, it's very unlikely that it's the same root cause since nothing significant has changed in the area that was changed to address this bug originally. Please open a new top-level issue and complete the questions in the bug report template and we can hopefully figure out what is causing problems for you.
Hi all !
I still have the same error on the v0.11.10. Is it a known bug ?
With Terraform 0.11.4 I get somewhat similar behavior - if I put a local inside a conditional, it fails to assign - although I don't understand why:
variable "env" {
default = "test"
}
locals {
# this gets actually retrieved from remote state.
id = "1234"
}
module demo1 {
...
authorizer_id = "${var.env == "test" ? "NO_ID" : "${local.id}" }"
}
I'm pretty sure TF before 0.12 doesn't do lazy evaluation, but still the local is defined. I'll continue to investigate :)
Edit:
Based on https://www.terraform.io/docs/configuration/locals.html
Perhaps I shouldn't try to interpolate "${local.id}" _inside_ another interpolation?
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 all!
Sorry for the delay in getting this out; we had to hold for another fix to be included in that release. It was included in today's 0.10.4 release.