forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixer_amazon_spot_price_product.go
69 lines (56 loc) · 1.61 KB
/
fixer_amazon_spot_price_product.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
67
68
69
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package fix
import (
"github.com/mitchellh/mapstructure"
)
// FixerAmazonSpotPriceProductDeprecation removes the deprecated "spot_price_auto_product" setting
// from Amazon builder templates
type FixerAmazonSpotPriceProductDeprecation struct{}
func (FixerAmazonSpotPriceProductDeprecation) DeprecatedOptions() map[string][]string {
return map[string][]string{
"*amazon*": []string{"spot_price_auto_product"},
}
}
func (FixerAmazonSpotPriceProductDeprecation) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
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
}
for _, builder := range tpl.Builders {
builderTypeRaw, ok := builder["type"]
if !ok {
continue
}
builderType, ok := builderTypeRaw.(string)
if !ok {
continue
}
buildersToFix := []string{"amazon-ebs", "amazon-ebssurrogate",
"amazon-ebsvolume", "amazon-instance"}
matched := false
for _, b := range buildersToFix {
if builderType == b {
matched = true
break
}
}
if !matched {
continue
}
_, ok = builder["spot_price_auto_product"]
if ok {
delete(builder, "spot_price_auto_product")
}
}
input["builders"] = tpl.Builders
return input, nil
}
func (FixerAmazonSpotPriceProductDeprecation) Synopsis() string {
return `Removes the deprecated "spot_price_auto_product" setting from Amazon builder templates`
}