feat(arm-builder): print warning on zone resiliency for currently not supported locations
This commit is contained in:
parent
f31031f6b1
commit
d79b54e46a
|
@ -139,6 +139,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
b.config.Location = *group.Location
|
b.config.Location = *group.Location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.config.validateLocationZoneResiliency(ui.Say)
|
||||||
|
|
||||||
if b.config.StorageAccount != "" {
|
if b.config.StorageAccount != "" {
|
||||||
account, err := b.getBlobAccount(ctx, azureClient, b.config.ResourceGroupName, b.config.StorageAccount)
|
account, err := b.getBlobAccount(ctx, azureClient, b.config.ResourceGroupName, b.config.StorageAccount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -725,3 +725,23 @@ func isValidAzureName(re *regexp.Regexp, rgn string) bool {
|
||||||
!strings.HasSuffix(rgn, ".") &&
|
!strings.HasSuffix(rgn, ".") &&
|
||||||
!strings.HasSuffix(rgn, "-")
|
!strings.HasSuffix(rgn, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) validateLocationZoneResiliency(say func(s string)) {
|
||||||
|
// Docs on regions that support Availibility Zones:
|
||||||
|
// https://docs.microsoft.com/en-us/azure/availability-zones/az-overview#regions-that-support-availability-zones
|
||||||
|
// Query technical names for locations:
|
||||||
|
// az account list-locations --query '[].name' -o tsv
|
||||||
|
|
||||||
|
var zones = make(map[string]struct{})
|
||||||
|
zones["westeurope"] = struct{}{}
|
||||||
|
zones["centralus"] = struct{}{}
|
||||||
|
zones["eastus2"] = struct{}{}
|
||||||
|
zones["francecentral"] = struct{}{}
|
||||||
|
zones["northeurope"] = struct{}{}
|
||||||
|
zones["southeastasia"] = struct{}{}
|
||||||
|
zones["westus2"] = struct{}{}
|
||||||
|
|
||||||
|
if _, ok := zones[c.Location]; !ok {
|
||||||
|
say(fmt.Sprintf("WARNING: Zone resiliency may not be supported in %s, checkout the docs at https://docs.microsoft.com/en-us/azure/availability-zones/", c.Location))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1681,7 +1681,42 @@ func TestConfigShouldRejectSharedImageGalleryWithVhdTarget(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log("expected an error if Shared Image Gallery source is used with VHD target", err)
|
t.Log("expected an error if Shared Image Gallery source is used with VHD target", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_GivenZoneNotSupportingResiliency_ConfigValidate_ShouldWarn(t *testing.T) {
|
||||||
|
builderValues := getArmBuilderConfiguration()
|
||||||
|
builderValues["managed_image_zone_resilient"] = "true"
|
||||||
|
builderValues["location"] = "ukwest"
|
||||||
|
|
||||||
|
c, _, err := newConfig(builderValues, getPackerConfiguration())
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("newConfig failed with %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var m = ""
|
||||||
|
c.validateLocationZoneResiliency(func(s string) { m = s })
|
||||||
|
|
||||||
|
if m != "WARNING: Zone resiliency may not be supported in ukwest, checkout the docs at https://docs.microsoft.com/en-us/azure/availability-zones/" {
|
||||||
|
t.Errorf("warning message not as expected: %s", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_GivenZoneSupportingResiliency_ConfigValidate_ShouldNotWarn(t *testing.T) {
|
||||||
|
builderValues := getArmBuilderConfiguration()
|
||||||
|
builderValues["managed_image_zone_resilient"] = "true"
|
||||||
|
builderValues["location"] = "westeurope"
|
||||||
|
|
||||||
|
c, _, err := newConfig(builderValues, getPackerConfiguration())
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("newConfig failed with %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var m = ""
|
||||||
|
c.validateLocationZoneResiliency(func(s string) { m = s })
|
||||||
|
|
||||||
|
if m != "" {
|
||||||
|
t.Errorf("warning message not as expected: %s", m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getArmBuilderConfiguration() map[string]string {
|
func getArmBuilderConfiguration() map[string]string {
|
||||||
|
|
Loading…
Reference in New Issue