2016-03-04 05:14:55 -05:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2016-05-06 23:32:18 -04:00
|
|
|
// Licensed under the MIT License. See the LICENSE file in builder/azure for license information.
|
2016-03-04 05:14:55 -05:00
|
|
|
|
|
|
|
package arm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-05-09 17:19:55 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2016-04-21 19:50:03 -04:00
|
|
|
"github.com/mitchellh/packer/builder/azure/common"
|
2016-03-10 20:46:22 -05:00
|
|
|
"github.com/mitchellh/packer/builder/azure/common/constants"
|
2016-03-04 05:14:55 -05:00
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StepDeleteResourceGroup struct {
|
|
|
|
client *AzureClient
|
2016-04-21 19:50:03 -04:00
|
|
|
delete func(resourceGroupName string, cancelCh <-chan struct{}) error
|
2016-03-04 05:14:55 -05:00
|
|
|
say func(message string)
|
|
|
|
error func(e error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewStepDeleteResourceGroup(client *AzureClient, ui packer.Ui) *StepDeleteResourceGroup {
|
|
|
|
var step = &StepDeleteResourceGroup{
|
|
|
|
client: client,
|
|
|
|
say: func(message string) { ui.Say(message) },
|
|
|
|
error: func(e error) { ui.Error(e.Error()) },
|
|
|
|
}
|
|
|
|
|
|
|
|
step.delete = step.deleteResourceGroup
|
|
|
|
return step
|
|
|
|
}
|
|
|
|
|
2016-04-21 19:50:03 -04:00
|
|
|
func (s *StepDeleteResourceGroup) deleteResourceGroup(resourceGroupName string, cancelCh <-chan struct{}) error {
|
|
|
|
_, err := s.client.GroupsClient.Delete(resourceGroupName, cancelCh)
|
2016-03-04 05:14:55 -05:00
|
|
|
|
2016-04-21 19:50:03 -04:00
|
|
|
return err
|
2016-03-04 05:14:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepDeleteResourceGroup) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
s.say("Deleting resource group ...")
|
|
|
|
|
|
|
|
var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string)
|
|
|
|
s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName))
|
|
|
|
|
2016-04-21 19:50:03 -04:00
|
|
|
result := common.StartInterruptibleTask(
|
|
|
|
func() bool { return common.IsStateCancelled(state) },
|
|
|
|
func(cancelCh <-chan struct{}) error { return s.delete(resourceGroupName, cancelCh) })
|
2016-03-04 05:14:55 -05:00
|
|
|
|
2016-05-09 17:19:55 -04:00
|
|
|
stepAction := processInterruptibleResult(result, s.error, state)
|
|
|
|
state.Put(constants.ArmIsResourceGroupCreated, false)
|
|
|
|
|
|
|
|
return stepAction
|
2016-03-04 05:14:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*StepDeleteResourceGroup) Cleanup(multistep.StateBag) {
|
|
|
|
}
|