Closed eliezio closed 4 years ago
Hello @eliezio, thanks for opening and trying out HCL2.
Currently this works but the locals
blocks have to be split:
variable "project_name" {
default = "test"
}
variable "name_prefix" {
default = "foo"
}
locals {
default_name_prefix = "${var.project_name}-web"
name_prefix = "${var.name_prefix != "" ? var.name_prefix : local.default_name_prefix}" // works
}
locals {
foo = "${local.default_name_prefix}" // YAY
bar = local.default_name_prefix // YAY
}
I think your example makes sense and think I should have also made this possible too. I'm going to fix this soon.
Hey @eliezio, it is not possible to use locals
within a same locals
block, this is due to a limitation/requirement of our HCL2 parsing library.
Again splitting the blocks should fix the issue:
locals {
default_name_prefix = "${var.project_name}-web"
name_prefix = "${var.name_prefix != "" ? var.name_prefix : local.default_name_prefix}" // works
}
locals {
foo = "${local.default_name_prefix}" // YAY
bar = local.default_name_prefix // YAY
}
I'm going to go ahead and close the issue.
Sorry all !!!
Ah wait, it works for Terraform ! We will try to investigate a little more.
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.
Overview of the Issue
Packer HCL parser fails to interpolate local variables referenced in other local variables.
Reproduction Steps
On the snippet below, based on the documentation example, Packer always fails if you replace the definition on line 10 by similar definitions on lines 11 or 12.
Packer version
From
packer --version
: 1.5.4Simplified Packer Buildfile
Included above.
Operating system and Environment details
macOS 10.15.3
Log Fragments and crash.log files