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