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