github.com/hashicorp/packer@v1.14.3/fix/fixer_azure_exclude_from_latest.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package fix
     5  
     6  import (
     7  	"strings"
     8  
     9  	"github.com/mitchellh/mapstructure"
    10  )
    11  
    12  // FixerAzureExcludeFromLatest fix the spelling of "exclude_from_latest"
    13  // template in an Azure builder
    14  type FixerAzureExcludeFromLatest struct{}
    15  
    16  func (FixerAzureExcludeFromLatest) DeprecatedOptions() map[string][]string {
    17  	return map[string][]string{
    18  		"Azure*": []string{"exlude_from_latest"},
    19  	}
    20  }
    21  
    22  func (FixerAzureExcludeFromLatest) Fix(input map[string]interface{}) (map[string]interface{}, error) {
    23  	// The type we'll decode into; we only care about builders
    24  	type template struct {
    25  		Builders []map[string]interface{}
    26  	}
    27  
    28  	// Decode the input into our structure, if we can
    29  	var tpl template
    30  	if err := mapstructure.Decode(input, &tpl); err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	for _, builder := range tpl.Builders {
    35  		builderTypeRaw, ok := builder["type"]
    36  		if !ok {
    37  			continue
    38  		}
    39  
    40  		builderType, ok := builderTypeRaw.(string)
    41  		if !ok {
    42  			continue
    43  		}
    44  
    45  		if !strings.HasPrefix(builderType, "azure-chroot") {
    46  			continue
    47  		}
    48  
    49  		if !strings.HasPrefix(builderType, "azure-chroot") {
    50  			continue
    51  		}
    52  
    53  		sharedImageDestination, ok := builder["shared_image_destination"].(map[string]interface{})
    54  		if !ok {
    55  			continue
    56  		}
    57  
    58  		excludeFromLatest, ok := sharedImageDestination["exlude_from_latest"]
    59  		if !ok {
    60  			continue
    61  		}
    62  
    63  		sharedImageDestination["exclude_from_latest"] = excludeFromLatest
    64  		delete(sharedImageDestination, "exlude_from_latest")
    65  
    66  		builder["shared_image_destination"] = sharedImageDestination
    67  	}
    68  
    69  	input["builders"] = tpl.Builders
    70  	return input, nil
    71  }
    72  
    73  func (FixerAzureExcludeFromLatest) Synopsis() string {
    74  	return `Changes "exlude_from_latest" to "exclude_from_latest" in Azure builders.`
    75  }