github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/fix/fixer_amazon_shutdown_behavior.go (about) 1 package fix 2 3 import ( 4 "github.com/mitchellh/mapstructure" 5 ) 6 7 // FixerAmazonShutdownBehavior fix the spelling of "shutdown_behavior" 8 // template in a Amazon builder 9 type FixerAmazonShutdownBehavior struct{} 10 11 func (FixerAmazonShutdownBehavior) Fix(input map[string]interface{}) (map[string]interface{}, error) { 12 // The type we'll decode into; we only care about builders 13 type template struct { 14 Builders []map[string]interface{} 15 } 16 17 // Decode the input into our structure, if we can 18 var tpl template 19 if err := mapstructure.Decode(input, &tpl); err != nil { 20 return nil, err 21 } 22 23 for _, builder := range tpl.Builders { 24 builderTypeRaw, ok := builder["type"] 25 if !ok { 26 continue 27 } 28 29 builderType, ok := builderTypeRaw.(string) 30 if !ok { 31 continue 32 } 33 34 if builderType != "amazon-ebs" && builderType != "amazon-ebsvolume" && builderType != "amazon-instance" && builderType != "amazon-chroot" { 35 continue 36 } 37 38 shutdownBehavior, ok := builder["shutdown_behaviour"] 39 40 if ok { 41 builder["shutdown_behavior"] = shutdownBehavior 42 delete(builder, "shutdown_behaviour") 43 } 44 } 45 46 input["builders"] = tpl.Builders 47 return input, nil 48 } 49 50 func (FixerAmazonShutdownBehavior) Synopsis() string { 51 return `Changes "shutdown_behaviour" to "shutdown_behavior" in Amazon builders.` 52 }