github.com/ddnomad/packer@v1.3.2/fix/fixer_hyperv_vmxc_typo.go (about) 1 package fix 2 3 import ( 4 "github.com/mitchellh/mapstructure" 5 ) 6 7 // FixerHypervVmxcTypo fixes the typo in "clone_from_vmxc_path" replacing 8 // it with "clone_from_vmcx_path" in Hyper-V VMCX builder templates 9 type FixerHypervVmxcTypo struct{} 10 11 func (FixerHypervVmxcTypo) Fix(input map[string]interface{}) (map[string]interface{}, error) { 12 // The type we'll decode into; we only care about builders 13 type template struct { 14 Builders []map[string]interface{} 15 } 16 17 // Decode the input into our structure, if we can 18 var tpl template 19 if err := mapstructure.Decode(input, &tpl); err != nil { 20 return nil, err 21 } 22 23 for _, builder := range tpl.Builders { 24 builderTypeRaw, ok := builder["type"] 25 if !ok { 26 continue 27 } 28 29 builderType, ok := builderTypeRaw.(string) 30 if !ok { 31 continue 32 } 33 34 if builderType != "hyperv-vmcx" { 35 continue 36 } 37 38 path, ok := builder["clone_from_vmxc_path"] 39 if ok { 40 delete(builder, "clone_from_vmxc_path") 41 builder["clone_from_vmcx_path"] = path 42 } 43 } 44 45 input["builders"] = tpl.Builders 46 return input, nil 47 } 48 49 func (FixerHypervVmxcTypo) Synopsis() string { 50 return `Fixes a typo replacing "clone_from_vmxc_path" with "clone_from_vmcx_path" ` + 51 `in Hyper-V VMCX builder templates` 52 }