2013-12-19 17:54:00 -05:00
|
|
|
package fix
|
|
|
|
|
2018-09-06 14:55:11 -04:00
|
|
|
import "github.com/mitchellh/mapstructure"
|
2013-12-19 17:54:00 -05:00
|
|
|
|
2018-03-13 04:28:26 -04:00
|
|
|
// FixerVagrantPPOverride is a Fixer that replaces the provider-specific
|
2013-12-19 17:54:00 -05:00
|
|
|
// overrides for the Vagrant post-processor with the new style introduced
|
|
|
|
// as part of Packer 0.5.0.
|
|
|
|
type FixerVagrantPPOverride struct{}
|
|
|
|
|
2020-10-09 20:01:55 -04:00
|
|
|
func (FixerVagrantPPOverride) DeprecatedOptions() map[string][]string {
|
|
|
|
return map[string][]string{}
|
2020-05-28 17:37:29 -04:00
|
|
|
}
|
|
|
|
|
2013-12-19 17:54:00 -05:00
|
|
|
func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
2018-09-06 14:55:11 -04:00
|
|
|
if input["post-processors"] == nil {
|
|
|
|
return input, nil
|
|
|
|
}
|
|
|
|
|
2013-12-19 17:54:00 -05:00
|
|
|
// Our template type we'll use for this fixer only
|
|
|
|
type template struct {
|
2018-09-05 15:08:40 -04:00
|
|
|
PP `mapstructure:",squash"`
|
2013-12-19 17:54:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the input into our structure, if we can
|
|
|
|
var tpl template
|
|
|
|
if err := mapstructure.Decode(input, &tpl); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:55:11 -04:00
|
|
|
pps := tpl.ppList()
|
2013-12-19 17:54:00 -05:00
|
|
|
|
|
|
|
// Go through each post-processor and make the fix if necessary
|
|
|
|
possible := []string{"aws", "digitalocean", "virtualbox", "vmware"}
|
|
|
|
for _, pp := range pps {
|
|
|
|
typeRaw, ok := pp["type"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if typeName, ok := typeRaw.(string); !ok {
|
|
|
|
continue
|
|
|
|
} else if typeName != "vagrant" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
overrides := make(map[string]interface{})
|
|
|
|
for _, name := range possible {
|
|
|
|
if _, ok := pp[name]; !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
overrides[name] = pp[name]
|
|
|
|
delete(pp, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(overrides) > 0 {
|
|
|
|
pp["override"] = overrides
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:55:11 -04:00
|
|
|
input["post-processors"] = tpl.PostProcessors
|
2013-12-19 17:54:00 -05:00
|
|
|
return input, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (FixerVagrantPPOverride) Synopsis() string {
|
|
|
|
return `Fixes provider-specific overrides for Vagrant post-processor`
|
|
|
|
}
|