diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go index 26f2e2ea1..b7856b29f 100644 --- a/builder/amazon/common/access_config.go +++ b/builder/amazon/common/access_config.go @@ -162,13 +162,6 @@ func (c *AccessConfig) Prepare(ctx *interpolate.Context) []error { fmt.Errorf("`access_key` and `secret_key` must both be either set or not set.")) } - if c.RawRegion != "" && !c.SkipValidation { - err := c.ValidateRegion(c.RawRegion) - if err != nil { - errs = append(errs, fmt.Errorf("error validating region: %s", err.Error())) - } - } - return errs } diff --git a/builder/amazon/common/ami_config.go b/builder/amazon/common/ami_config.go index 5fbac557a..a03c3a789 100644 --- a/builder/amazon/common/ami_config.go +++ b/builder/amazon/common/ami_config.go @@ -96,14 +96,6 @@ func (c *AMIConfig) Prepare(accessConfig *AccessConfig, ctx *interpolate.Context func (c *AMIConfig) prepareRegions(accessConfig *AccessConfig) (errs []error) { if len(c.AMIRegions) > 0 { - if !c.AMISkipRegionValidation { - // Verify the regions are real - err := accessConfig.ValidateRegion(c.AMIRegions...) - if err != nil { - errs = append(errs, fmt.Errorf("error validating regions: %v", err)) - } - } - regionSet := make(map[string]struct{}) regions := make([]string, 0, len(c.AMIRegions)) diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 3e1580430..7e2ba9610 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -86,11 +86,17 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { - session, err := b.config.Session() if err != nil { return nil, err } + if !b.config.AMISkipRegionValidation { + regionsToValidate := append(b.config.AMIRegions, b.config.RawRegion) + err := b.config.AccessConfig.ValidateRegion(regionsToValidate...) + if err != nil { + return nil, fmt.Errorf("error validating regions: %v", err) + } + } ec2conn := ec2.New(session) // Setup the state bag and initial state for the steps