diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index 83028dee3..4c67f7fa5 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -221,8 +221,6 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack NewStepSnapshotDataDisks(azureClient, ui, &b.config), NewStepCaptureImage(azureClient, ui), NewStepPublishToSharedImageGallery(azureClient, ui, &b.config), - NewStepDeleteOSDisk(azureClient, ui), - NewStepDeleteAdditionalDisks(azureClient, ui), } } else if b.config.OSType == constants.Target_Windows { steps = []multistep.Step{ @@ -263,8 +261,6 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack NewStepSnapshotDataDisks(azureClient, ui, &b.config), NewStepCaptureImage(azureClient, ui), NewStepPublishToSharedImageGallery(azureClient, ui, &b.config), - NewStepDeleteOSDisk(azureClient, ui), - NewStepDeleteAdditionalDisks(azureClient, ui), ) } else { return nil, fmt.Errorf("Builder does not support the os_type '%s'", b.config.OSType) diff --git a/builder/azure/arm/step_delete_additional_disks.go b/builder/azure/arm/step_delete_additional_disks.go index 0c8b26b3a..3a3ba5a34 100644 --- a/builder/azure/arm/step_delete_additional_disks.go +++ b/builder/azure/arm/step_delete_additional_disks.go @@ -80,25 +80,26 @@ func (s *StepDeleteAdditionalDisk) Run(ctx context.Context, state multistep.Stat s.say("Failed to delete the managed Additional Disk!") return processStepResult(err, s.error, state) } + continue + } + + u, err := url.Parse(additionaldisk) + if err != nil { + s.say("Failed to parse the Additional Disk's VHD URI!") + return processStepResult(err, s.error, state) + } + + xs := strings.Split(u.Path, "/") + if len(xs) < 3 { + err = errors.New("Failed to parse Additional Disk's VHD URI!") } else { - u, err := url.Parse(additionaldisk) - if err != nil { - s.say("Failed to parse the Additional Disk's VHD URI!") - return processStepResult(err, s.error, state) - } + var storageAccountName = xs[1] + var blobName = strings.Join(xs[2:], "/") - xs := strings.Split(u.Path, "/") - if len(xs) < 3 { - err = errors.New("Failed to parse Additional Disk's VHD URI!") - } else { - var storageAccountName = xs[1] - var blobName = strings.Join(xs[2:], "/") - - err = s.delete(storageAccountName, blobName) - } - if err != nil { - return processStepResult(err, s.error, state) - } + err = s.delete(storageAccountName, blobName) + } + if err != nil { + return processStepResult(err, s.error, state) } } return multistep.ActionContinue diff --git a/builder/azure/arm/step_deploy_template.go b/builder/azure/arm/step_deploy_template.go index daa12275c..5d3994cc4 100644 --- a/builder/azure/arm/step_deploy_template.go +++ b/builder/azure/arm/step_deploy_template.go @@ -90,7 +90,12 @@ 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() + if err := deploymentOperations.Next(); err != nil { + ui.Error(fmt.Sprintf("Error deleting resources. Please delete them manually.\n\n"+ + "Name: %s\n"+ + "Error: %s", resourceGroupName, err)) + break + } continue } @@ -164,20 +169,20 @@ func (s *StepDeployTemplate) deleteTemplate(ctx context.Context, state multistep func (s *StepDeployTemplate) getImageDetails(ctx context.Context, resourceGroupName string, computeName string) (string, string, error) { //We can't depend on constants.ArmOSDiskVhd being set - var imageName string - var imageType string + var imageName, imageType string vm, err := s.client.VirtualMachinesClient.Get(ctx, resourceGroupName, computeName, "") if err != nil { return imageName, imageType, err - } else { - if vm.StorageProfile.OsDisk.Vhd != nil { - imageType = "image" - imageName = *vm.StorageProfile.OsDisk.Vhd.URI - } else { - imageType = "Microsoft.Compute/disks" - imageName = *vm.StorageProfile.OsDisk.ManagedDisk.ID - } } + + if vm.StorageProfile.OsDisk.Vhd != nil { + imageType = "image" + imageName = *vm.StorageProfile.OsDisk.Vhd.URI + } else { + imageType = "Microsoft.Compute/disks" + imageName = *vm.StorageProfile.OsDisk.ManagedDisk.ID + } + return imageType, imageName, nil }