From f31031f6b1cface81c247eb772bba28f5ac7918f Mon Sep 17 00:00:00 2001 From: Manuel Riezebosch Date: Thu, 17 Jan 2019 09:01:42 +0100 Subject: [PATCH] feat(arm-builder): zone resilient from config --- builder/azure/arm/config.go | 4 ++ builder/azure/arm/config_test.go | 45 ++++++++++++++++++++++ website/source/docs/builders/azure.html.md | 3 ++ 3 files changed, 52 insertions(+) diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 862226245..340e9b46d 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -107,6 +107,7 @@ type Config struct { ManagedImageOSDiskSnapshotName string `mapstructure:"managed_image_os_disk_snapshot_name"` ManagedImageDataDiskSnapshotPrefix string `mapstructure:"managed_image_data_disk_snapshot_prefix"` manageImageLocation string + ManagedImageZoneResilient bool `mapstructure:"managed_image_zone_resilient"` // Deployment AzureTags map[string]*string `mapstructure:"azure_tags"` @@ -196,6 +197,9 @@ func (c *Config) toImageParameters() *compute.Image { SourceVirtualMachine: &compute.SubResource{ ID: to.StringPtr(c.toVMID()), }, + StorageProfile: &compute.ImageStorageProfile{ + ZoneResilient: to.BoolPtr(c.ManagedImageZoneResilient), + }, }, Location: to.StringPtr(c.Location), Tags: c.AzureTags, diff --git a/builder/azure/arm/config_test.go b/builder/azure/arm/config_test.go index bf1bd5023..64d59e4eb 100644 --- a/builder/azure/arm/config_test.go +++ b/builder/azure/arm/config_test.go @@ -794,6 +794,51 @@ func TestConfigShouldRejectExcessiveTagValueLength(t *testing.T) { } } +func TestConfigZoneResilientShouldDefaultToFalse(t *testing.T) { + config := map[string]interface{}{ + "managed_image_name": "ignore", + "managed_image_resource_group_name": "ignore", + "build_resource_group_name": "ignore", + "image_publisher": "igore", + "image_offer": "ignore", + "image_sku": "ignore", + "os_type": "linux", + } + + c, _, err := newConfig(config, getPackerConfiguration()) + if err != nil { + t.Fatal(err) + } + + p := c.toImageParameters() + if *p.ImageProperties.StorageProfile.ZoneResilient { + t.Fatal("expected zone resilient default to be false") + } +} + +func TestConfigZoneResilientSetFromConfig(t *testing.T) { + config := map[string]interface{}{ + "managed_image_name": "ignore", + "managed_image_resource_group_name": "ignore", + "build_resource_group_name": "ignore", + "image_publisher": "igore", + "image_offer": "ignore", + "image_sku": "ignore", + "os_type": "linux", + "managed_image_zone_resilient": true, + } + + c, _, err := newConfig(config, getPackerConfiguration()) + if err != nil { + t.Fatal(err) + } + + p := c.toImageParameters() + if *p.ImageProperties.StorageProfile.ZoneResilient == false { + t.Fatal("expected managed image zone resilient to be true from config") + } +} + func TestConfigShouldRejectMissingCustomDataFile(t *testing.T) { config := map[string]interface{}{ "capture_name_prefix": "ignore", diff --git a/website/source/docs/builders/azure.html.md b/website/source/docs/builders/azure.html.md index 8caf44848..c218e6d43 100644 --- a/website/source/docs/builders/azure.html.md +++ b/website/source/docs/builders/azure.html.md @@ -333,6 +333,9 @@ Providing `temp_resource_group_name` or `location` in combination with is set, snapshot of the data disk(s) is created with the same prefix as this value before the VM is captured. +- `managed_image_zone_resilient` (bool) Store the image in zone-resilient storage. You need to create it + in a region that supports [availability zones](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview). + ## Basic Example Here is a basic example for Azure.