github.com/hashicorp/packer@v1.14.3/fix/fixer_parallels_deprecations.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fix 5 6 import ( 7 "github.com/mitchellh/mapstructure" 8 ) 9 10 // FixerParallelsDeprecations removes "parallels_tools_host_path" from a 11 // template in a Parallels builder and changes "guest_os_distribution" to 12 // "guest_os_type", possibly overwriting any existing "guest_os_type" 13 type FixerParallelsDeprecations struct{} 14 15 func (FixerParallelsDeprecations) DeprecatedOptions() map[string][]string { 16 return map[string][]string{ 17 "packer.parallels": []string{"parallels_tools_host_path", "guest_os_distribution"}, 18 } 19 } 20 21 func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) { 22 // The type we'll decode into; we only care about builders 23 type template struct { 24 Builders []map[string]interface{} 25 } 26 27 // Decode the input into our structure, if we can 28 var tpl template 29 if err := mapstructure.Decode(input, &tpl); err != nil { 30 return nil, err 31 } 32 33 for _, builder := range tpl.Builders { 34 builderTypeRaw, ok := builder["type"] 35 if !ok { 36 continue 37 } 38 39 builderType, ok := builderTypeRaw.(string) 40 if !ok { 41 continue 42 } 43 44 if builderType != "parallels-iso" && builderType != "parallels-pvm" { 45 continue 46 } 47 48 _, ok = builder["parallels_tools_host_path"] 49 if ok { 50 delete(builder, "parallels_tools_host_path") 51 } 52 53 guestOsDistribution, ok := builder["guest_os_distribution"] 54 55 if ok { 56 builder["guest_os_type"] = guestOsDistribution 57 delete(builder, "guest_os_distribution") 58 } 59 } 60 61 input["builders"] = tpl.Builders 62 return input, nil 63 } 64 65 func (FixerParallelsDeprecations) Synopsis() string { 66 return `Removes deprecated "parallels_tools_host_path" from Parallels builders and changes "guest_os_distribution" to "guest_os_type".` 67 }