github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/fix/fixer_amazon_enhanced_networking.go (about)

     1  package fix
     2  
     3  import (
     4  	"github.com/mitchellh/mapstructure"
     5  )
     6  
     7  // FixerAmazonEnhancedNetworking is a Fixer that replaces the "enhanced_networking" configuration key
     8  // with the clearer "ena_support".  This disambiguates ena_support from sriov_support.
     9  type FixerAmazonEnhancedNetworking struct{}
    10  
    11  func (FixerAmazonEnhancedNetworking) Fix(input map[string]interface{}) (map[string]interface{}, error) {
    12  	// Our template type we'll use for this fixer only
    13  	type template struct {
    14  		Builders []map[string]interface{}
    15  	}
    16  
    17  	// Decode the input into our structure, if we can
    18  	var tpl template
    19  	if err := mapstructure.Decode(input, &tpl); err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	// Go through each builder and replace the enhanced_networking if we can
    24  	for _, builder := range tpl.Builders {
    25  		enhancedNetworkingRaw, ok := builder["enhanced_networking"]
    26  		if !ok {
    27  			continue
    28  		}
    29  		enhancedNetworkingString, ok := enhancedNetworkingRaw.(bool)
    30  		if !ok {
    31  			// TODO: error?
    32  			continue
    33  		}
    34  
    35  		delete(builder, "enhanced_networking")
    36  		builder["ena_support"] = enhancedNetworkingString
    37  	}
    38  
    39  	input["builders"] = tpl.Builders
    40  	return input, nil
    41  }
    42  
    43  func (FixerAmazonEnhancedNetworking) Synopsis() string {
    44  	return `Replaces "enhanced_networking" in builders with "ena_support"`
    45  }