diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index fd6bd9edb..7f69d5d10 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -519,6 +519,10 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) { } } + if c.TempResourceGroupName != "" && c.BuildResourceGroupName != "" { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("The settings temp_resource_group_name and build_resource_group_name cannot both be defined. Please define one or neither.")) + } + ///////////////////////////////////////////// // Compute toInt := func(b bool) int { diff --git a/builder/azure/arm/config_test.go b/builder/azure/arm/config_test.go index b7523f655..20954632e 100644 --- a/builder/azure/arm/config_test.go +++ b/builder/azure/arm/config_test.go @@ -899,6 +899,31 @@ func TestConfigShouldAcceptManagedImageStorageAccountTypes(t *testing.T) { } } +func TestConfigShouldRejectTempAndBuildResourceGroupName(t *testing.T) { + config := map[string]interface{}{ + "capture_name_prefix": "ignore", + "capture_container_name": "ignore", + "image_offer": "ignore", + "image_publisher": "ignore", + "image_sku": "ignore", + "location": "ignore", + "storage_account": "ignore", + "resource_group_name": "ignore", + "subscription_id": "ignore", + "communicator": "none", + + // custom may define one or the other, but not both + "temp_resource_group_name": "rgn00", + "build_resource_group_name": "rgn00", + } + + _, _, err := newConfig(config, getPackerConfiguration()) + if err == nil { + t.Fatal("expected config to reject the use of both temp_resource_group_name and build_resource_group_name") + } +} + + func getArmBuilderConfiguration() map[string]string { m := make(map[string]string) for _, v := range requiredConfigValues { diff --git a/website/source/docs/builders/azure.html.md b/website/source/docs/builders/azure.html.md index 8f9d23442..a4068702a 100644 --- a/website/source/docs/builders/azure.html.md +++ b/website/source/docs/builders/azure.html.md @@ -134,8 +134,9 @@ When creating a managed image the following two options are required. assigned. Knowing the resource group and VM name allows one to execute commands to update the VM during a Packer build, e.g. attach a resource disk to the VM. -- `temp_resource_group_name` (string) name assigned to the temporary resource group created during the build. If this value is not set, a random - value will be assigned. Cannot be used together with `build_resource_group_name`. +- `temp_resource_group_name` (string) name assigned to the temporary resource group created during the build. If this + value is not set, a random value will be assigned. This resource group is deleted at the end of the build. Cannot be + used together with `build_resource_group_name`. - `tenant_id` (string) The account identifier with which your `client_id` and `subscription_id` are associated. If not specified, `tenant_id` will be looked up using `subscription_id`.