normalize replication regions

This commit is contained in:
Amrita Dutta 2019-06-18 06:01:22 +00:00
parent 59a0f7f6e6
commit f1f93f0665
1 changed files with 8 additions and 2 deletions

View File

@ -141,7 +141,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
}
// validate that Shared Gallery Image exists before publishing to SIG
if b.config.SharedGalleryDestination.SigDestinationGalleryName != "" {
if b.config.isManagedImage() && b.config.SharedGalleryDestination.SigDestinationGalleryName != "" {
_, err = azureClient.GalleryImagesClient.Get(ctx, b.config.SharedGalleryDestination.SigDestinationResourceGroup, b.config.SharedGalleryDestination.SigDestinationGalleryName, b.config.SharedGalleryDestination.SigDestinationImageName)
if err != nil {
return nil, fmt.Errorf("the Shared Gallery Image to which to publish the managed image version to does not exists in the resource group %s", b.config.SharedGalleryDestination.SigDestinationResourceGroup)
@ -428,9 +428,15 @@ func getObjectIdFromToken(ui packer.Ui, token *adal.ServicePrincipalToken) strin
func verifyAndUpdateReplicationRegions(regions []string, mustHaveRegion string) []string {
for _, region := range regions {
if strings.EqualFold(region, mustHaveRegion) {
// change region to lower-case and strip spaces
normalizedRegion := normalizeAzureRegion(region)
if strings.EqualFold(normalizedRegion, mustHaveRegion) {
return regions
}
}
return append(regions, mustHaveRegion)
}
func normalizeAzureRegion(name string) string {
return strings.ToLower(strings.Replace(name, " ", "", -1))
}