From b23d6c9589e4917617facae9ebcaafe15186a102 Mon Sep 17 00:00:00 2001 From: Hariharan Jayaraman Date: Wed, 6 Jun 2018 15:25:19 -0700 Subject: [PATCH] fixing infinite loop issue deleting existing resources if we have a empty target resource --- builder/azure/arm/builder_acc_test.go | 42 +++++++++++++++++++ .../azure/arm/step_delete_resource_group.go | 1 + builder/azure/arm/step_deploy_template.go | 1 + 3 files changed, 44 insertions(+) diff --git a/builder/azure/arm/builder_acc_test.go b/builder/azure/arm/builder_acc_test.go index 0b1f85656..8f0c605f9 100644 --- a/builder/azure/arm/builder_acc_test.go +++ b/builder/azure/arm/builder_acc_test.go @@ -38,6 +38,14 @@ func TestBuilderAcc_ManagedDisk_Windows(t *testing.T) { }) } +func TestBuilderAcc_ManagedDisk_Windows_Build_Resource_Group(t *testing.T) { + builderT.Test(t, builderT.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Builder: &Builder{}, + Template: testBuilderAccManagedDiskWindowsBuildResourceGroup, + }) +} + func TestBuilderAcc_ManagedDisk_Windows_DeviceLogin(t *testing.T) { if os.Getenv(DeviceLoginAcceptanceTest) == "" { t.Skip(fmt.Sprintf( @@ -126,6 +134,40 @@ const testBuilderAccManagedDiskWindows = ` }] } ` +const testBuilderAccManagedDiskWindowsBuildResourceGroup = ` +{ + "variables": { + "client_id": "{{env ` + "`ARM_CLIENT_ID`" + `}}", + "client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}", + "subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}" + }, + "builders": [{ + "type": "test", + + "client_id": "{{user ` + "`client_id`" + `}}", + "client_secret": "{{user ` + "`client_secret`" + `}}", + "subscription_id": "{{user ` + "`subscription_id`" + `}}", + + "build_resource_group_name" : "packer-acceptance-test", + "managed_image_resource_group_name": "packer-acceptance-test", + "managed_image_name": "testBuilderAccManagedDiskWindows-{{timestamp}}", + + "os_type": "Windows", + "image_publisher": "MicrosoftWindowsServer", + "image_offer": "WindowsServer", + "image_sku": "2012-R2-Datacenter", + + "communicator": "winrm", + "winrm_use_ssl": "true", + "winrm_insecure": "true", + "winrm_timeout": "3m", + "winrm_username": "packer", + "async_resourcegroup_delete": "true", + + "vm_size": "Standard_DS2_v2" + }] +} +` const testBuilderAccManagedDiskWindowsDeviceLogin = ` { diff --git a/builder/azure/arm/step_delete_resource_group.go b/builder/azure/arm/step_delete_resource_group.go index 56d2f15c5..c5b92fcf1 100644 --- a/builder/azure/arm/step_delete_resource_group.go +++ b/builder/azure/arm/step_delete_resource_group.go @@ -82,6 +82,7 @@ func (s *StepDeleteResourceGroup) deleteDeploymentResources(ctx context.Context, deploymentOperation := deploymentOperations.Value() // Sometimes an empty operation is added to the list by Azure if deploymentOperation.Properties.TargetResource == nil { + deploymentOperations.Next() continue } diff --git a/builder/azure/arm/step_deploy_template.go b/builder/azure/arm/step_deploy_template.go index e089ad4bf..83590afd7 100644 --- a/builder/azure/arm/step_deploy_template.go +++ b/builder/azure/arm/step_deploy_template.go @@ -185,6 +185,7 @@ func (s *StepDeployTemplate) Cleanup(state multistep.StateBag) { deploymentOperation := deploymentOperations.Value() // Sometimes an empty operation is added to the list by Azure if deploymentOperation.Properties.TargetResource == nil { + deploymentOperations.Next() continue } ui.Say(fmt.Sprintf(" -> %s : '%s'",