make sure locals are evaluated only once variables are + test this (#8918)

fix #8898
This commit is contained in:
Adrien Delorme 2020-03-19 15:30:34 +01:00 committed by GitHub
parent ad8dafa3bd
commit d068430abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -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"]
}
}

View File

@ -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 {