github.com/hashicorp/packer@v1.14.3/fix/fixer_hyperv_cpu_and_ram_naming.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 // FizerHypervCPUandRAM changes `cpu` to `cpus` and `ram_size` to `memory` 11 type FizerHypervCPUandRAM struct{} 12 13 func (FizerHypervCPUandRAM) DeprecatedOptions() map[string][]string { 14 return map[string][]string{ 15 "MSOpenTech.hyperv": []string{"cpu", "ram_size"}, 16 } 17 } 18 19 func (FizerHypervCPUandRAM) Fix(input map[string]interface{}) (map[string]interface{}, error) { 20 // The type we'll decode into; we only care about builders 21 type template struct { 22 Builders []map[string]interface{} 23 } 24 25 // Decode the input into our structure, if we can 26 var tpl template 27 if err := mapstructure.Decode(input, &tpl); err != nil { 28 return nil, err 29 } 30 31 for _, builder := range tpl.Builders { 32 builderTypeRaw, ok := builder["type"] 33 if !ok { 34 continue 35 } 36 37 builderType, ok := builderTypeRaw.(string) 38 if !ok { 39 continue 40 } 41 42 if builderType != "hyperv-vmcx" && builderType != "hyperv-iso" { 43 continue 44 } 45 46 ncpus, ok := builder["cpu"] 47 if ok { 48 delete(builder, "cpu") 49 builder["cpus"] = ncpus 50 } 51 52 memory, ok := builder["ram_size"] 53 if ok { 54 delete(builder, "ram_size") 55 builder["memory"] = memory 56 } 57 } 58 59 input["builders"] = tpl.Builders 60 return input, nil 61 } 62 63 func (FizerHypervCPUandRAM) Synopsis() string { 64 return `Replaces "cpu" with "cpus" and "ram_size" with "memory"` + 65 `in Hyper-V VMCX builder templates` 66 }