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 }