github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/step_delete_resource_group.go (about) 1 // Copyright (c) Microsoft Corporation. All rights reserved. 2 // Licensed under the MIT License. See the LICENSE file in builder/azure for license information. 3 4 package arm 5 6 import ( 7 "fmt" 8 9 "github.com/mitchellh/multistep" 10 "github.com/mitchellh/packer/builder/azure/common/constants" 11 "github.com/mitchellh/packer/packer" 12 ) 13 14 type StepDeleteResourceGroup struct { 15 client *AzureClient 16 delete func(resourceGroupName string) error 17 say func(message string) 18 error func(e error) 19 } 20 21 func NewStepDeleteResourceGroup(client *AzureClient, ui packer.Ui) *StepDeleteResourceGroup { 22 var step = &StepDeleteResourceGroup{ 23 client: client, 24 say: func(message string) { ui.Say(message) }, 25 error: func(e error) { ui.Error(e.Error()) }, 26 } 27 28 step.delete = step.deleteResourceGroup 29 return step 30 } 31 32 func (s *StepDeleteResourceGroup) deleteResourceGroup(resourceGroupName string) error { 33 res, err := s.client.GroupsClient.Delete(resourceGroupName) 34 if err != nil { 35 return err 36 } 37 38 s.client.GroupsClient.PollAsNeeded(res.Response) 39 return nil 40 } 41 42 func (s *StepDeleteResourceGroup) Run(state multistep.StateBag) multistep.StepAction { 43 s.say("Deleting resource group ...") 44 45 var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string) 46 47 s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName)) 48 49 err := s.delete(resourceGroupName) 50 if err != nil { 51 state.Put(constants.Error, err) 52 s.error(err) 53 54 return multistep.ActionHalt 55 } 56 57 return multistep.ActionContinue 58 } 59 60 func (*StepDeleteResourceGroup) Cleanup(multistep.StateBag) { 61 }