fix
This commit is contained in:
parent
82a1f017aa
commit
1788d29567
|
@ -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()
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue