diff --git a/fix/fixer.go b/fix/fixer.go index 4bcbaac2f..4b0b1ad09 100644 --- a/fix/fixer.go +++ b/fix/fixer.go @@ -43,6 +43,7 @@ func init() { "hyperv-cpu-and-ram": new(FizerHypervCPUandRAM), "vmware-compaction": new(FixerVMwareCompaction), "clean-image-name": new(FixerCleanImageName), + "spot-price-auto-product": new(FixerAmazonSpotPriceProductDeprecation), } FixerOrder = []string{ @@ -67,5 +68,6 @@ func init() { "vmware-compaction", "hyperv-cpu-and-ram", "clean-image-name", + "spot-price-auto-product", } } diff --git a/fix/fixer_amazon_spot_price_product.go b/fix/fixer_amazon_spot_price_product.go new file mode 100644 index 000000000..2ed961589 --- /dev/null +++ b/fix/fixer_amazon_spot_price_product.go @@ -0,0 +1,60 @@ +package fix + +import ( + "github.com/mitchellh/mapstructure" +) + +// FixerAmazonSpotPriceProductDeprecation removes the deprecated "vhd_temp_path" setting +// from Amazon builder templates +type FixerAmazonSpotPriceProductDeprecation struct{} + +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` +} diff --git a/website/source/partials/builders/_aws-spot-docs.html.md b/website/source/partials/builders/_aws-spot-docs.html.md index c68731230..e4bfdc44f 100644 --- a/website/source/partials/builders/_aws-spot-docs.html.md +++ b/website/source/partials/builders/_aws-spot-docs.html.md @@ -16,9 +16,15 @@ this to `auto` for Packer to automatically discover the best spot price or to "0" to use an on demand instance (default). -- `spot_price_auto_product` (string) - Required if `spot_price` is set to - `auto`. This tells Packer what sort of AMI you're launching to find the - best spot price. This must be one of: `Linux/UNIX`, `SUSE Linux`, +- `spot_price_auto_product` (string) - Deprecated. Prior to v1.4.3, was + required if `spot_price` is set to `auto`. + + If you are using Packer v1.4.3 or later, simply remove this from your + template; it is no longer necessary based on recent changes to how Amazon + calculates spot prices. + + Prior to version 1.4.3, This told Packer what sort of AMI you're launching + to find the best spot price. This must be one of: `Linux/UNIX`, `SUSE Linux`, `Windows`, `Linux/UNIX (Amazon VPC)`, `SUSE Linux (Amazon VPC)`, `Windows (Amazon VPC)`