github.com/Hashicorp/packer@v1.3.2/fix/fixer_amazon_shutdown_behavior.go (about) 1 package fix 2 3 import ( 4 "strings" 5 6 "github.com/mitchellh/mapstructure" 7 ) 8 9 // FixerAmazonShutdownBehavior fix the spelling of "shutdown_behavior" 10 // template in a Amazon builder 11 type FixerAmazonShutdownBehavior struct{} 12 13 func (FixerAmazonShutdownBehavior) Fix(input map[string]interface{}) (map[string]interface{}, error) { 14 // The type we'll decode into; we only care about builders 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 for _, builder := range tpl.Builders { 26 builderTypeRaw, ok := builder["type"] 27 if !ok { 28 continue 29 } 30 31 builderType, ok := builderTypeRaw.(string) 32 if !ok { 33 continue 34 } 35 36 if !strings.HasPrefix(builderType, "amazon-") { 37 continue 38 } 39 40 shutdownBehavior, ok := builder["shutdown_behaviour"] 41 42 if ok { 43 builder["shutdown_behavior"] = shutdownBehavior 44 delete(builder, "shutdown_behaviour") 45 } 46 } 47 48 input["builders"] = tpl.Builders 49 return input, nil 50 } 51 52 func (FixerAmazonShutdownBehavior) Synopsis() string { 53 return `Changes "shutdown_behaviour" to "shutdown_behavior" in Amazon builders.` 54 }