From 55812fe8a5be63bee7c12a930f959b1bac0b6a16 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Wed, 12 Aug 2020 11:30:15 -0400 Subject: [PATCH] Handle error of deferred deletion --- builder/azure/arm/step_deploy_template.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/builder/azure/arm/step_deploy_template.go b/builder/azure/arm/step_deploy_template.go index 255903098..003514e70 100644 --- a/builder/azure/arm/step_deploy_template.go +++ b/builder/azure/arm/step_deploy_template.go @@ -55,7 +55,12 @@ func (s *StepDeployTemplate) Run(ctx context.Context, state multistep.StateBag) } func (s *StepDeployTemplate) Cleanup(state multistep.StateBag) { - defer s.deleteTemplate(context.Background(), state) + defer func() { + err := s.deleteTemplate(context.Background(), state) + if err != nil { + s.say(s.client.LastError.Error()) + } + }() //Only clean up if this was an existing resource group and the resource group //is marked as created @@ -167,10 +172,6 @@ func (s *StepDeployTemplate) deleteTemplate(ctx context.Context, state multistep err = f.WaitForCompletionRef(ctx, s.client.DeploymentsClient.Client) } - if err != nil { - s.say(s.client.LastError.Error()) - } - return err }