diff --git a/common/step_provision.go b/common/step_provision.go index 7f51a20c5..c6c039eea 100644 --- a/common/step_provision.go +++ b/common/step_provision.go @@ -48,6 +48,8 @@ func PlaceholderData() map[string]string { placeholderData[name] = fmt.Sprintf("{{.%s}}", name) } + placeholderData["ID"] = "{{.ID}}" + return placeholderData } @@ -58,6 +60,7 @@ type StepProvision struct { func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} { hookData := map[string]interface{}{} // Read communicator data into hook data + // state.GetOK("id") commConf, ok := state.GetOk("communicator_config") if !ok { log.Printf("Unable to load config from state to populate provisionHookData") @@ -94,7 +97,6 @@ func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBa ui := state.Get("ui").(packer.Ui) hookData := PopulateProvisionHookData(state) - log.Printf("Megan hookdata is %T", hookData) // Run the provisioner in a goroutine so we can continually check // for cancellations... diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 609d35f4a..107875023 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -43,6 +43,7 @@ var FuncGens = map[string]interface{}{ "consul_key": funcGenConsul, "vault": funcGenVault, "sed": funcGenSed, + "generated": funcGenGenerated, "replace": replace, "replace_all": replace_all, @@ -162,6 +163,13 @@ func funcGenTemplateDir(ctx *Context) interface{} { } } +func funcGenGenerated(ctx *Context) interface{} { + return func(k string) (string, error) { + // Return the key inside braces _without_ the generated func attached + return fmt.Sprintf("{{.%s}}", k), nil + } +} + func funcGenTimestamp(ctx *Context) interface{} { return func() string { return strconv.FormatInt(InitTime.Unix(), 10)