diff --git a/common/step_provision.go b/common/step_provision.go index c6c039eea..60f7bbffd 100644 --- a/common/step_provision.go +++ b/common/step_provision.go @@ -53,10 +53,6 @@ func PlaceholderData() map[string]string { return placeholderData } -type StepProvision struct { - Comm packer.Communicator -} - func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} { hookData := map[string]interface{}{} // Read communicator data into hook data @@ -76,13 +72,24 @@ func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} } // Loop over all field values and retrieve them from the ssh config for fieldName, _ := range pd { + if fieldName == "ID" { + continue + } fVal := v.FieldByName(fieldName) - hookData[fieldName] = fVal.Interface() + if fVal.IsZero() { + log.Printf("Megan NONINTERFACABLE fVal is %#v", fVal) + } else { + hookData[fieldName] = fVal.Interface() + } } return hookData } +type StepProvision struct { + Comm packer.Communicator +} + func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBag, hooktype string) multistep.StepAction { // hooktype will be either packer.HookProvision or packer.HookCleanupProvision comm := s.Comm diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 107875023..341c4630b 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -3,6 +3,7 @@ package interpolate import ( "errors" "fmt" + "log" "os" "path/filepath" "strconv" @@ -164,9 +165,21 @@ 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 + return func(s string) (string, error) { + log.Printf("Megan context data is %#v", ctx.Data) + if data, ok := ctx.Data.(map[string]string); ok { + // PlaceholderData has been passed into generator, and we can check + // the value against the placeholder data to make sure that it is + // valid + if heldPlace, ok := data[s]; ok { + return heldPlace, nil + } else { + return "", fmt.Errorf("loaded data, but couldnt find winrm in it", s) + } + } + + return "", fmt.Errorf("Error validating computed variable: the given "+ + "variable %s will not be passed into your plugin.", s) } }