clean up a few final issues with info sharing
This commit is contained in:
parent
25711ed7d0
commit
cd7abf1f9e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue