diff --git a/helper/common/shared_state.go b/helper/common/shared_state.go index dce05beec..10f3803ae 100644 --- a/helper/common/shared_state.go +++ b/helper/common/shared_state.go @@ -10,7 +10,7 @@ import ( // This is used in the BasicPlaceholderData() func in the packer/provisioner.go // To force users to access generated data via the "generated" func. const PlaceholderMsg = "To set this dynamically in the Packer template, " + - "you must use the `generated` function" + "you must use the `build` function" // Used to set variables which we need to access later in the build, where // state bag and config information won't work diff --git a/helper/config/decode.go b/helper/config/decode.go index 92681be24..5205bf266 100644 --- a/helper/config/decode.go +++ b/helper/config/decode.go @@ -163,7 +163,7 @@ func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []inte placeholderData := raws[len(raws)-1] if pd, ok := placeholderData.(map[string]string); ok { if uuid, ok := pd["PackerRunUUID"]; ok { - if strings.Contains(uuid, "Generated_PackerRunUUID.") { + if strings.Contains(uuid, "Build_PackerRunUUID.") { cast := make(map[interface{}]interface{}) for k, v := range pd { cast[k] = v @@ -178,12 +178,13 @@ func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []inte // map[interface]interface, not a map[string]string if pd, ok := placeholderData.(map[interface{}]interface{}); ok { if uuid, ok := pd["PackerRunUUID"]; ok { - if strings.Contains(uuid.(string), "Generated_PackerRunUUID.") { + if strings.Contains(uuid.(string), "Build_PackerRunUUID.") { raws = raws[:len(raws)-1] return pd, raws } } } + return nil, raws } diff --git a/packer/provisioner.go b/packer/provisioner.go index 2246f3a78..68f5a2946 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -53,7 +53,7 @@ type ProvisionHook struct { // data. func BasicPlaceholderData() map[string]string { placeholderData := map[string]string{} - msg := "Generated_%s. " + common.PlaceholderMsg + msg := "Build_%s. " + common.PlaceholderMsg placeholderData["ID"] = fmt.Sprintf(msg, "ID") // The following correspond to communicator-agnostic functions that are // part of the SSH and WinRM communicator implementations. These functions diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 4306b200e..9dcd5061d 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -166,6 +166,19 @@ func funcGenTemplateDir(ctx *Context) interface{} { func funcGenBuild(ctx *Context) interface{} { return func(s string) (string, error) { + if data, ok := ctx.Data.(map[string]string); ok { + if heldPlace, ok := data[s]; ok { + // If we're in the first interpolation pass, the goal is to + // make sure that we pass the value through. + // TODO match against an actual string constant + if strings.Contains(heldPlace, common.PlaceholderMsg) { + return fmt.Sprintf("{{.%s}}", s), nil + } else { + return heldPlace, nil + } + } + return "", fmt.Errorf("loaded data, but couldnt find %s in it.", s) + } if data, ok := ctx.Data.(map[interface{}]interface{}); ok { // PlaceholderData has been passed into generator, so if the given // key already exists in data, then we know it's an "allowed" key