github.com/hashicorp/packer@v1.14.3/fix/fixer_amazon_spot_price_product.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fix 5 6 import ( 7 "github.com/mitchellh/mapstructure" 8 ) 9 10 // FixerAmazonSpotPriceProductDeprecation removes the deprecated "spot_price_auto_product" setting 11 // from Amazon builder templates 12 type FixerAmazonSpotPriceProductDeprecation struct{} 13 14 func (FixerAmazonSpotPriceProductDeprecation) DeprecatedOptions() map[string][]string { 15 return map[string][]string{ 16 "*amazon*": []string{"spot_price_auto_product"}, 17 } 18 } 19 20 func (FixerAmazonSpotPriceProductDeprecation) Fix(input map[string]interface{}) (map[string]interface{}, error) { 21 // The type we'll decode into; we only care about builders 22 type template struct { 23 Builders []map[string]interface{} 24 } 25 26 // Decode the input into our structure, if we can 27 var tpl template 28 if err := mapstructure.Decode(input, &tpl); err != nil { 29 return nil, err 30 } 31 32 for _, builder := range tpl.Builders { 33 builderTypeRaw, ok := builder["type"] 34 if !ok { 35 continue 36 } 37 38 builderType, ok := builderTypeRaw.(string) 39 if !ok { 40 continue 41 } 42 43 buildersToFix := []string{"amazon-ebs", "amazon-ebssurrogate", 44 "amazon-ebsvolume", "amazon-instance"} 45 46 matched := false 47 for _, b := range buildersToFix { 48 if builderType == b { 49 matched = true 50 break 51 } 52 } 53 if !matched { 54 continue 55 } 56 57 _, ok = builder["spot_price_auto_product"] 58 if ok { 59 delete(builder, "spot_price_auto_product") 60 } 61 } 62 63 input["builders"] = tpl.Builders 64 return input, nil 65 } 66 67 func (FixerAmazonSpotPriceProductDeprecation) Synopsis() string { 68 return `Removes the deprecated "spot_price_auto_product" setting from Amazon builder templates` 69 }