diff --git a/command/test-fixtures/var-arg/fuit_builder.pkr.hcl b/command/test-fixtures/var-arg/fruit_builder.pkr.hcl similarity index 67% rename from command/test-fixtures/var-arg/fuit_builder.pkr.hcl rename to command/test-fixtures/var-arg/fruit_builder.pkr.hcl index 8aff9951d..63ece8a56 100644 --- a/command/test-fixtures/var-arg/fuit_builder.pkr.hcl +++ b/command/test-fixtures/var-arg/fruit_builder.pkr.hcl @@ -3,6 +3,10 @@ variable "fruit" { type = string } +locals { + fruit = var.fruit +} + source "null" "builder" { communicator = "none" } @@ -13,6 +17,6 @@ build { ] provisioner "shell-local" { - inline = ["echo ${var.fruit} > ${var.fruit}.txt"] + inline = ["echo ${local.fruit} > ${local.fruit}.txt"] } } diff --git a/hcl2template/parser.go b/hcl2template/parser.go index d7d2591ba..5ea9a18a5 100644 --- a/hcl2template/parser.go +++ b/hcl2template/parser.go @@ -94,18 +94,17 @@ func (p *Parser) parse(filename string, varFiles []string, argVars map[string]st // Decode variable blocks so that they are available later on. Here locals // can use input variables so we decode them firsthand. + var locals []*Local { for _, file := range files { diags = append(diags, cfg.decodeInputVariables(file)...) } - var locals []*Local for _, file := range files { moreLocals, morediags := cfg.parseLocalVariables(file) diags = append(diags, morediags...) locals = append(locals, moreLocals...) } - diags = append(diags, cfg.evaluateLocalVariables(locals)...) } // parse var files @@ -151,6 +150,7 @@ func (p *Parser) parse(filename string, varFiles []string, argVars map[string]st diags = append(diags, moreDiags...) _, moreDiags = cfg.LocalVariables.Values() diags = append(diags, moreDiags...) + diags = append(diags, cfg.evaluateLocalVariables(locals)...) // decode the actual content for _, file := range files {