diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go index d1f5b6ffb..7c2bc9304 100644 --- a/builder/amazon/common/access_config.go +++ b/builder/amazon/common/access_config.go @@ -17,11 +17,12 @@ import ( // AccessConfig is for common configuration related to AWS access type AccessConfig struct { - AccessKey string `mapstructure:"access_key"` - SecretKey string `mapstructure:"secret_key"` - RawRegion string `mapstructure:"region"` - Token string `mapstructure:"token"` - ProfileName string `mapstructure:"profile"` + AccessKey string `mapstructure:"access_key"` + SecretKey string `mapstructure:"secret_key"` + RawRegion string `mapstructure:"region"` + SkipValidation bool `mapstructure:"skip_region_validation"` + Token string `mapstructure:"token"` + ProfileName string `mapstructure:"profile"` } // Config returns a valid aws.Config object for access to AWS services, or @@ -65,8 +66,10 @@ func (c *AccessConfig) Config() (*aws.Config, error) { // the region from the instance metadata if possible. func (c *AccessConfig) Region() (string, error) { if c.RawRegion != "" { - if valid := ValidateRegion(c.RawRegion); valid == false { - return "", fmt.Errorf("Not a valid region: %s", c.RawRegion) + if !c.SkipValidation { + if valid := ValidateRegion(c.RawRegion); valid == false { + return "", fmt.Errorf("Not a valid region: %s", c.RawRegion) + } } return c.RawRegion, nil } @@ -82,7 +85,7 @@ func (c *AccessConfig) Region() (string, error) { func (c *AccessConfig) Prepare(ctx *interpolate.Context) []error { var errs []error - if c.RawRegion != "" { + if c.RawRegion != "" && !c.SkipValidation { if valid := ValidateRegion(c.RawRegion); valid == false { errs = append(errs, fmt.Errorf("Unknown region: %s", c.RawRegion)) } diff --git a/builder/amazon/common/access_config_test.go b/builder/amazon/common/access_config_test.go index dd20e9af9..20d4851ba 100644 --- a/builder/amazon/common/access_config_test.go +++ b/builder/amazon/common/access_config_test.go @@ -24,4 +24,17 @@ func TestAccessConfigPrepare_Region(t *testing.T) { if err := c.Prepare(nil); err != nil { t.Fatalf("shouldn't have err: %s", err) } + + c.RawRegion = "custom" + if err := c.Prepare(nil); err == nil { + t.Fatalf("should have err") + } + + c.RawRegion = "custom" + c.SkipValidation = true + if err := c.Prepare(nil); err != nil { + t.Fatalf("shouldn't have err: %s", err) + } + c.SkipValidation = false + } diff --git a/builder/amazon/common/ami_config.go b/builder/amazon/common/ami_config.go index 377201902..078dbefaa 100644 --- a/builder/amazon/common/ami_config.go +++ b/builder/amazon/common/ami_config.go @@ -8,16 +8,17 @@ import ( // AMIConfig is for common configuration related to creating AMIs. type AMIConfig struct { - AMIName string `mapstructure:"ami_name"` - AMIDescription string `mapstructure:"ami_description"` - AMIVirtType string `mapstructure:"ami_virtualization_type"` - AMIUsers []string `mapstructure:"ami_users"` - AMIGroups []string `mapstructure:"ami_groups"` - AMIProductCodes []string `mapstructure:"ami_product_codes"` - AMIRegions []string `mapstructure:"ami_regions"` - AMITags map[string]string `mapstructure:"tags"` - AMIEnhancedNetworking bool `mapstructure:"enhanced_networking"` - AMIForceDeregister bool `mapstructure:"force_deregister"` + AMIName string `mapstructure:"ami_name"` + AMIDescription string `mapstructure:"ami_description"` + AMIVirtType string `mapstructure:"ami_virtualization_type"` + AMIUsers []string `mapstructure:"ami_users"` + AMIGroups []string `mapstructure:"ami_groups"` + AMIProductCodes []string `mapstructure:"ami_product_codes"` + AMIRegions []string `mapstructure:"ami_regions"` + AMISkipRegionValidation bool `mapstructure:"skip_region_validation"` + AMITags map[string]string `mapstructure:"tags"` + AMIEnhancedNetworking bool `mapstructure:"enhanced_networking"` + AMIForceDeregister bool `mapstructure:"force_deregister"` } func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error { @@ -39,10 +40,12 @@ func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error { // Mark that we saw the region regionSet[region] = struct{}{} - // Verify the region is real - if valid := ValidateRegion(region); valid == false { - errs = append(errs, fmt.Errorf("Unknown region: %s", region)) - continue + if !c.AMISkipRegionValidation { + // Verify the region is real + if valid := ValidateRegion(region); valid == false { + errs = append(errs, fmt.Errorf("Unknown region: %s", region)) + continue + } } regions = append(regions, region) diff --git a/builder/amazon/common/ami_config_test.go b/builder/amazon/common/ami_config_test.go index 54210fca9..77158c41c 100644 --- a/builder/amazon/common/ami_config_test.go +++ b/builder/amazon/common/ami_config_test.go @@ -49,4 +49,12 @@ func TestAMIConfigPrepare_regions(t *testing.T) { if !reflect.DeepEqual(c.AMIRegions, expected) { t.Fatalf("bad: %#v", c.AMIRegions) } + + c.AMIRegions = []string{"custom"} + c.AMISkipRegionValidation = true + if err := c.Prepare(nil); err != nil { + t.Fatal("shouldn't have error") + } + c.AMISkipRegionValidation = false + } diff --git a/website/source/docs/builders/amazon-chroot.html.md b/website/source/docs/builders/amazon-chroot.html.md index 8482004c6..3570a1f0f 100644 --- a/website/source/docs/builders/amazon-chroot.html.md +++ b/website/source/docs/builders/amazon-chroot.html.md @@ -146,6 +146,9 @@ builder. - `root_volume_size` (integer) - The size of the root volume for the chroot environment, and the resulting AMI +- `skip_region_validation` (boolean) - Set to true if you want to skip + validation of the ami_regions configuration option. Defaults to false. + - `tags` (object of key/value strings) - Tags applied to the AMI. ## Basic Example diff --git a/website/source/docs/builders/amazon-ebs.html.md b/website/source/docs/builders/amazon-ebs.html.md index 1529acd2a..d44033e4a 100644 --- a/website/source/docs/builders/amazon-ebs.html.md +++ b/website/source/docs/builders/amazon-ebs.html.md @@ -166,6 +166,9 @@ builder. described above. Note that if this is specified, you must omit the `security_group_id`. +- `skip_region_validation` (boolean) - Set to true if you want to skip + validation of the region configuration option. Defaults to false. + - `spot_price` (string) - The maximum hourly price to pay for a spot instance to create the AMI. Spot instances are a type of instance that EC2 starts when the current spot price is less than the maximum price you specify. Spot diff --git a/website/source/docs/builders/amazon-instance.html.md b/website/source/docs/builders/amazon-instance.html.md index fd173310f..887f03b2b 100644 --- a/website/source/docs/builders/amazon-instance.html.md +++ b/website/source/docs/builders/amazon-instance.html.md @@ -191,6 +191,9 @@ builder. described above. Note that if this is specified, you must omit the `security_group_id`. +- `skip_region_validation` (boolean) - Set to true if you want to skip + validation of the region configuration option. Defaults to false. + - `spot_price` (string) - The maximum hourly price to launch a spot instance to create the AMI. It is a type of instances that EC2 starts when the maximum price that you specify exceeds the current spot price. Spot price