Allow to use build variables in a post processor (#11323)

* hcl: add test to verify that build.name can be used in a pp

* allow to use build vars in post processors
pull/11326/head
Adrien Delorme 4 years ago committed by GitHub
parent e99e038a72
commit 254e020b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -415,6 +415,17 @@ func TestBuild(t *testing.T) {
},
},
},
{
name: "hcl - using build variables in post-processor",
args: []string{
testFixture("hcl", "build-var-in-pp.pkr.hcl"),
},
fileCheck: fileCheck{
expectedContent: map[string]string{
"example.2.txt": two,
},
},
},
}
for _, tt := range tc {

@ -0,0 +1,12 @@
source "null" "example" {
communicator = "none"
}
build {
name = "example"
sources = ["source.null.example"]
post-processor "shell-local" {
inline = ["echo 2 > ${build.name}.2.txt"]
}
}

@ -31,6 +31,9 @@ func (p *HCL2PostProcessor) HCL2Prepare(buildVars map[string]interface{}) error
if len(buildVars) > 0 {
ectx = p.evalContext.NewChild()
buildValues := map[string]cty.Value{}
if !p.evalContext.Variables[buildAccessor].IsNull() {
buildValues = p.evalContext.Variables[buildAccessor].AsValueMap()
}
for k, v := range buildVars {
val, err := ConvertPluginConfigValueToHCLValue(v)
if err != nil {

Loading…
Cancel
Save