From 06525dd8855f3e0532918b11e61a3a9d2ad4b4d7 Mon Sep 17 00:00:00 2001 From: Amrita Dutta Date: Fri, 9 Nov 2018 19:28:37 +0000 Subject: [PATCH] adding logs in the steps --- builder/azure/arm/step_snapshot_data_disks.go | 23 +++++++++++++++++-- builder/azure/arm/step_snapshot_os_disk.go | 23 ++++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/builder/azure/arm/step_snapshot_data_disks.go b/builder/azure/arm/step_snapshot_data_disks.go index df9a5bfaf..4294cc489 100644 --- a/builder/azure/arm/step_snapshot_data_disks.go +++ b/builder/azure/arm/step_snapshot_data_disks.go @@ -2,6 +2,7 @@ package arm import ( "context" + "fmt" "strconv" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute" @@ -46,15 +47,32 @@ func (s *StepSnapshotDataDisks) createDataDiskSnapshot(ctx context.Context, reso if err != nil { s.say(s.client.LastError.Error()) + return err } - return f.WaitForCompletion(ctx, s.client.SnapshotsClient.Client) + err = f.WaitForCompletion(ctx, s.client.SnapshotsClient.Client) + + if err != nil { + s.say(s.client.LastError.Error()) + return err + } + + createdSnapshot, err := f.Result(s.client.SnapshotsClient) + + if err != nil { + s.say(s.client.LastError.Error()) + return err + } + + s.say(fmt.Sprintf(" -> Managed Image OS Disk Snapshot : '%s'", *(createdSnapshot.ID))) + + return nil } func (s *StepSnapshotDataDisks) Run(ctx context.Context, stateBag multistep.StateBag) multistep.StepAction { s.say("Taking snapshot of OS disk ...") - var resourceGroupName = stateBag.Get(constants.ArmResourceGroupName).(string) + var resourceGroupName = stateBag.Get(constants.ArmManagedImageResourceGroupName).(string) var location = stateBag.Get(constants.ArmLocation).(string) var tags = stateBag.Get(constants.ArmTags).(map[string]*string) var additionalDisks = stateBag.Get(constants.ArmAdditionalDiskVhds).([]string) @@ -70,6 +88,7 @@ func (s *StepSnapshotDataDisks) Run(ctx context.Context, stateBag multistep.Stat return multistep.ActionHalt } + } return multistep.ActionContinue diff --git a/builder/azure/arm/step_snapshot_os_disk.go b/builder/azure/arm/step_snapshot_os_disk.go index 5fa9f6b0b..ebb5e0486 100644 --- a/builder/azure/arm/step_snapshot_os_disk.go +++ b/builder/azure/arm/step_snapshot_os_disk.go @@ -2,7 +2,7 @@ package arm import ( "context" - + "fmt" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute" "github.com/Azure/go-autorest/autorest/to" "github.com/hashicorp/packer/builder/azure/common/constants" @@ -45,15 +45,32 @@ func (s *StepSnapshotOSDisk) createSnapshot(ctx context.Context, resourceGroupNa if err != nil { s.say(s.client.LastError.Error()) + return err } - return f.WaitForCompletion(ctx, s.client.SnapshotsClient.Client) + err = f.WaitForCompletion(ctx, s.client.SnapshotsClient.Client) + + if err != nil { + s.say(s.client.LastError.Error()) + return err + } + + createdSnapshot, err := f.Result(s.client.SnapshotsClient) + + if err != nil { + s.say(s.client.LastError.Error()) + return err + } + + s.say(fmt.Sprintf(" -> Managed Image OS Disk Snapshot : '%s'", *(createdSnapshot.ID))) + + return nil } func (s *StepSnapshotOSDisk) Run(ctx context.Context, stateBag multistep.StateBag) multistep.StepAction { s.say("Taking snapshot of OS disk ...") - var resourceGroupName = stateBag.Get(constants.ArmResourceGroupName).(string) + var resourceGroupName = stateBag.Get(constants.ArmManagedImageResourceGroupName).(string) var location = stateBag.Get(constants.ArmLocation).(string) var tags = stateBag.Get(constants.ArmTags).(map[string]*string) var srcUriVhd = stateBag.Get(constants.ArmOSDiskVhd).(string)