diff --git a/builder/azure/arm/artifact.go b/builder/azure/arm/artifact.go index b1ae13e3a..6a3463ec3 100644 --- a/builder/azure/arm/artifact.go +++ b/builder/azure/arm/artifact.go @@ -3,6 +3,7 @@ package arm import ( "bytes" "fmt" + "log" "net/url" "path" "strings" @@ -60,16 +61,19 @@ func NewManagedImageArtifact(osType, resourceGroup, name, location, id, osDiskSn if keepOSDisk { if template == nil { - return nil, fmt.Errorf("nil capture template") + log.Printf("artifact error: nil capture template") + return &res, nil } if len(template.Resources) != 1 { - return nil, fmt.Errorf("malformed capture template, expected one resource") + log.Printf("artifact error: malformed capture template, expected one resource") + return &res, nil } vhdUri, err := url.Parse(template.Resources[0].Properties.StorageProfile.OSDisk.Image.Uri) if err != nil { - return nil, err + log.Printf("artifact error: Error parsing osdisk url: %s", err) + return &res, nil } res.OSDiskUri = vhdUri.String() diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index 7ca702884..7b67f4862 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -332,6 +332,17 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) template.(*CaptureTemplate), getSasUrlFunc) } + return NewManagedImageArtifact(b.config.OSType, + b.config.ManagedImageResourceGroupName, + b.config.ManagedImageName, + b.config.Location, + managedImageID, + b.config.ManagedImageOSDiskSnapshotName, + b.config.ManagedImageDataDiskSnapshotPrefix, + generatedData, + b.stateBag.Get(constants.ArmKeepOSDisk).(bool), + nil, + getSasUrlFunc) } else if template, ok := b.stateBag.GetOk(constants.ArmCaptureTemplate); ok { return NewArtifact( template.(*CaptureTemplate), diff --git a/builder/azure/arm/step_deploy_template_test.go b/builder/azure/arm/step_deploy_template_test.go index a29ef2a0c..088b9901a 100644 --- a/builder/azure/arm/step_deploy_template_test.go +++ b/builder/azure/arm/step_deploy_template_test.go @@ -117,6 +117,7 @@ func TestStepDeployTemplateCleanupShouldDeleteManagedOSImageInExistingResourceGr stateBag.Put(constants.ArmIsManagedImage, true) stateBag.Put(constants.ArmIsExistingResourceGroup, true) stateBag.Put(constants.ArmIsResourceGroupCreated, true) + stateBag.Put(constants.ArmKeepOSDisk, false) stateBag.Put("ui", packersdk.TestUi(t)) testSubject.Cleanup(stateBag) @@ -133,6 +134,7 @@ func TestStepDeployTemplateCleanupShouldDeleteManagedOSImageInTemporaryResourceG stateBag.Put(constants.ArmIsManagedImage, true) stateBag.Put(constants.ArmIsExistingResourceGroup, false) stateBag.Put(constants.ArmIsResourceGroupCreated, true) + stateBag.Put(constants.ArmKeepOSDisk, false) stateBag.Put("ui", packersdk.TestUi(t)) testSubject.Cleanup(stateBag) @@ -149,6 +151,7 @@ func TestStepDeployTemplateCleanupShouldDeleteVHDOSImageInExistingResourceGroup( stateBag.Put(constants.ArmIsManagedImage, false) stateBag.Put(constants.ArmIsExistingResourceGroup, true) stateBag.Put(constants.ArmIsResourceGroupCreated, true) + stateBag.Put(constants.ArmKeepOSDisk, false) stateBag.Put("ui", packersdk.TestUi(t)) testSubject.Cleanup(stateBag) @@ -165,6 +168,7 @@ func TestStepDeployTemplateCleanupShouldVHDOSImageInTemporaryResourceGroup(t *te stateBag.Put(constants.ArmIsManagedImage, false) stateBag.Put(constants.ArmIsExistingResourceGroup, false) stateBag.Put(constants.ArmIsResourceGroupCreated, true) + stateBag.Put(constants.ArmKeepOSDisk, false) stateBag.Put("ui", packersdk.TestUi(t)) testSubject.Cleanup(stateBag)