move region validation to run so that we don't break validation when we don't have aws creds set

This commit is contained in:
Megan Marsh 2018-11-20 15:01:28 -08:00
parent fbde30c8c0
commit fbb3d526e3
3 changed files with 7 additions and 16 deletions

View File

@ -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
}

View File

@ -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))

View File

@ -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