mirror of https://github.com/hashicorp/packer
The logic for evaluating local variables used to rely on their definition order, with some edge cases. Typically `locals` blocks define multiple local variables, which don't necessarily appear in the same order at evaluation as within the template, leading to inconsistent behaviour, as the order in which those are added to the list of local variables is non-deterministic. To avoid this problem, we change how local variables are evaluated, and we're adopting a workflow similar to datasources, where the local variables first build a list of direct dependencies. Then when evaluation happens, we evaluate all the dependencies recursively for each local variable, which takes care of this issue. As with Datasources, we add a cap to the recursion: 10. I.e. if the evaluation of a single variable provokes an infinite recursion, we stop at that point and return an error to the user, telling them to fix their template.nywilken.document-tmpdir
parent
5673af108f
commit
14cf4b40d4
@ -0,0 +1,14 @@
|
||||
package packer_test
|
||||
|
||||
func (ts *PackerTestSuite) TestEvalLocalsOrder() {
|
||||
ts.SkipNoAcc()
|
||||
|
||||
pluginDir, cleanup := ts.MakePluginDir()
|
||||
defer cleanup()
|
||||
|
||||
ts.PackerCommand().UsePluginDir(pluginDir).
|
||||
Runs(10).
|
||||
Stdin("local.test_local\n").
|
||||
SetArgs("console", "./templates/locals_no_order.pkr.hcl").
|
||||
Assert(MustSucceed(), Grep("\\[\\]", grepStdout, grepInvert))
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
locals {
|
||||
test_local = can(local.test_data) ? local.test_data : []
|
||||
|
||||
test_data = [
|
||||
{ key = "value" }
|
||||
]
|
||||
}
|
||||
Loading…
Reference in new issue