github.com/hashicorp/packer@v1.14.3/fix/fixer_amazon_enhanced_networking.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 // FixerAmazonEnhancedNetworking is a Fixer that replaces the "enhanced_networking" configuration key 13 // with the clearer "ena_support". This disambiguates ena_support from sriov_support. 14 type FixerAmazonEnhancedNetworking struct{} 15 16 func (FixerAmazonEnhancedNetworking) DeprecatedOptions() map[string][]string { 17 return map[string][]string{ 18 "*amazon*": []string{"enhanced_networking"}, 19 } 20 } 21 22 func (FixerAmazonEnhancedNetworking) Fix(input map[string]interface{}) (map[string]interface{}, error) { 23 // Our template type we'll use for this fixer only 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 // Go through each builder and replace the enhanced_networking if we can 35 for _, builder := range tpl.Builders { 36 builderTypeRaw, ok := builder["type"] 37 if !ok { 38 continue 39 } 40 41 builderType, ok := builderTypeRaw.(string) 42 if !ok { 43 continue 44 } 45 46 if !strings.HasPrefix(builderType, "amazon-") { 47 continue 48 } 49 enhancedNetworkingRaw, ok := builder["enhanced_networking"] 50 if !ok { 51 continue 52 } 53 enhancedNetworkingString, ok := enhancedNetworkingRaw.(bool) 54 if !ok { 55 // TODO: error? 56 continue 57 } 58 59 delete(builder, "enhanced_networking") 60 builder["ena_support"] = enhancedNetworkingString 61 } 62 63 input["builders"] = tpl.Builders 64 return input, nil 65 } 66 67 func (FixerAmazonEnhancedNetworking) Synopsis() string { 68 return `Replaces "enhanced_networking" in builders with "ena_support"` 69 }