Fix artifact output

This commit is contained in:
Paul Meyer 2020-04-09 20:54:50 +00:00
parent 47107e6355
commit 89a8238a07
2 changed files with 32 additions and 3 deletions

View File

@ -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

View File

@ -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)
}
}