diff --git a/builder/azure/chroot/builder.go b/builder/azure/chroot/builder.go index f8a31b1c2..ab234783b 100644 --- a/builder/azure/chroot/builder.go +++ b/builder/azure/chroot/builder.go @@ -387,13 +387,21 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack artifact := &azcommon.Artifact{ BuilderIdValue: BuilderID, StateData: map[string]interface{}{"generated_data": state.Get("generated_data")}, + AzureClientSet: azcli, } - resources := []string{} if b.config.ImageResourceID != "" { - resources = append(resources, b.config.ImageResourceID) + artifact.Resources = append(artifact.Resources, b.config.ImageResourceID) } if e, _ := b.config.SharedImageGalleryDestination.Validate(""); len(e) == 0 { - resources = append(resources, b.config.SharedImageGalleryDestination.ResourceID(info.SubscriptionID)) + artifact.Resources = append(artifact.Resources, b.config.SharedImageGalleryDestination.ResourceID(info.SubscriptionID)) + } + if b.config.SkipCleanup { + if d, ok := state.GetOk(stateBagKey_OSDiskResourceID); ok { + artifact.Resources = append(artifact.Resources, d.(string)) + } + if d, ok := state.GetOk(stateBagKey_OSDiskSnapshotResourceID); ok { + artifact.Resources = append(artifact.Resources, d.(string)) + } } return artifact, nil diff --git a/builder/azure/common/artifact_test.go b/builder/azure/common/artifact_test.go new file mode 100644 index 000000000..a4fe439c6 --- /dev/null +++ b/builder/azure/common/artifact_test.go @@ -0,0 +1,21 @@ +package common + +import ( + "testing" +) + +func TestArtifact_String(t *testing.T) { + a := &Artifact{ + Resources: []string{ + "/subscriptions/4674464f-6024-43ae-903c-f6eed761be04/resourceGroups/rg/providers/Microsoft.Compute/disks/PackerTemp-osdisk-1586461959", + "/subscriptions/4674464f-6024-43ae-903c-f6eed761be04/resourceGroups/images/providers/Microsoft.Compute/galleries/testgallery/images/myUbuntu/versions/1.0.10", + }, + } + want := `Azure resources created: +/subscriptions/4674464f-6024-43ae-903c-f6eed761be04/resourcegroups/images/providers/microsoft.compute/galleries/testgallery/images/myubuntu/versions/1.0.10 +/subscriptions/4674464f-6024-43ae-903c-f6eed761be04/resourcegroups/rg/providers/microsoft.compute/disks/packertemp-osdisk-1586461959 +` + if got := a.String(); got != want { + t.Errorf("Artifact.String() = %v, want %v", got, want) + } +}