github.com/hashicorp/packer@v1.14.3/fix/fixer_hyperv_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  // FixerHypervDeprecations removes the deprecated "vhd_temp_path" setting
    11  // from Hyper-V ISO builder templates
    12  type FixerHypervDeprecations struct{}
    13  
    14  func (FixerHypervDeprecations) DeprecatedOptions() map[string][]string {
    15  	return map[string][]string{
    16  		"MSOpenTech.hyperv": []string{"vhd_temp_path"},
    17  	}
    18  }
    19  
    20  func (FixerHypervDeprecations) 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-iso" {
    44  			continue
    45  		}
    46  
    47  		_, ok = builder["vhd_temp_path"]
    48  		if ok {
    49  			delete(builder, "vhd_temp_path")
    50  		}
    51  	}
    52  
    53  	input["builders"] = tpl.Builders
    54  	return input, nil
    55  }
    56  
    57  func (FixerHypervDeprecations) Synopsis() string {
    58  	return `Removes the deprecated "vhd_temp_path" setting from Hyper-V ISO builder templates`
    59  }