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