github.com/hashicorp/packer@v1.14.3/fix/fixer_qemu_host_port.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 // FixerQEMUHostPort updates ssh_host_port_min and ssh_host_port_max to host_port_min and host_port_max for QEMU builders 11 type FixerQEMUHostPort struct{} 12 13 func (FixerQEMUHostPort) Fix(input map[string]interface{}) (map[string]interface{}, error) { 14 type template struct { 15 Builders []map[string]interface{} 16 } 17 18 // Decode the input into our structure, if we can 19 var tpl template 20 if err := mapstructure.Decode(input, &tpl); err != nil { 21 return nil, err 22 } 23 24 for _, builder := range tpl.Builders { 25 builderTypeRaw, ok := builder["type"] 26 if !ok { 27 continue 28 } 29 30 builderType, ok := builderTypeRaw.(string) 31 if !ok { 32 continue 33 } 34 35 if builderType != "qemu" { 36 continue 37 } 38 39 // replace ssh_host_port_min with host_port_min if it exists 40 sshHostPortMin, ok := builder["ssh_host_port_min"] 41 if ok { 42 delete(builder, "ssh_host_port_min") 43 builder["host_port_min"] = sshHostPortMin 44 } 45 46 // replace ssh_host_port_min with host_port_min if it exists 47 sshHostPortMax, ok := builder["ssh_host_port_max"] 48 if ok { 49 delete(builder, "ssh_host_port_max") 50 builder["host_port_max"] = sshHostPortMax 51 } 52 } 53 54 input["builders"] = tpl.Builders 55 return input, nil 56 } 57 58 func (FixerQEMUHostPort) Synopsis() string { 59 return `Updates ssh_host_port_min and ssh_host_port_max to host_port_min and host_port_max` 60 } 61 62 func (FixerQEMUHostPort) DeprecatedOptions() map[string][]string { 63 return map[string][]string{ 64 "transcend.qemu": []string{"ssh_host_port_max", "ssh_host_port_min"}, 65 } 66 }