From 9a34fd15ca86c9736fa3427a0ffc4fc66e0a5ddc Mon Sep 17 00:00:00 2001 From: Christopher Boumenot Date: Sun, 13 Aug 2017 00:27:51 -0700 Subject: [PATCH] azure: improve docs and validation Closes #5186 --- builder/azure/arm/config.go | 4 ++++ builder/azure/arm/config_test.go | 20 ++++++++++++++++++++ website/source/docs/builders/azure.html.md | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 668a4240a..ce05ae571 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -534,6 +534,10 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Specify either a VHD (image_url), Image Reference (image_publisher, image_offer, image_sku) or a Managed Disk (custom_managed_disk_image_name, custom_managed_disk_resource_group_name")) } + if isImageUrl && c.ManagedImageResourceGroupName != "" { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("A managed image must be created from a managed image, it cannot be created from a VHD.")) + } + if c.ImageUrl == "" && c.CustomManagedImageName == "" { if c.ImagePublisher == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("An image_publisher must be specified")) diff --git a/builder/azure/arm/config_test.go b/builder/azure/arm/config_test.go index 86e4301bc..00659b1e8 100644 --- a/builder/azure/arm/config_test.go +++ b/builder/azure/arm/config_test.go @@ -792,6 +792,26 @@ func TestConfigShouldRejectVhdAndManagedImageOutput(t *testing.T) { } } +// If the user specified a build of a VHD, but started with a managed image it should be rejected. +func TestConfigShouldRejectManagedImageSourceAndVhdOutput(t *testing.T) { + config := map[string]interface{}{ + "image_url": "ignore", + "location": "ignore", + "subscription_id": "ignore", + "communicator": "none", + "managed_image_resource_group_name": "ignore", + "managed_image_name": "ignore", + + // Does not matter for this test case, just pick one. + "os_type": constants.Target_Linux, + } + + _, _, err := newConfig(config, getPackerConfiguration()) + if err == nil { + t.Fatal("expected config to reject VHD and Managed Image build") + } +} + func TestConfigShouldRejectCustomAndPlatformManagedImageBuild(t *testing.T) { config := map[string]interface{}{ "custom_managed_image_resource_group_name": "ignore", diff --git a/website/source/docs/builders/azure.html.md b/website/source/docs/builders/azure.html.md index 96fb59ba8..abda2a5f1 100644 --- a/website/source/docs/builders/azure.html.md +++ b/website/source/docs/builders/azure.html.md @@ -50,7 +50,10 @@ builder. #### VHD or Managed Image -The Azure builder can create either a VHD, or a managed image. When creating a VHD the following two options are required. +The Azure builder can create either a VHD, or a managed image. If you +are creating a VHD, you **must** start with a VHD. Likewise, if you +want to create a managed image you **must** start with a managed +image. When creating a VHD the following two options are required. - `capture_container_name` (string) Destination container name. Essentially the "directory" where your VHD will be organized in Azure. The captured VHD's URL will be https://.blob.core.windows.net/system/Microsoft.Compute/Images//.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.vhd.