github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/step_create_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/Azure/azure-sdk-for-go/arm/resources/resources" 10 "github.com/mitchellh/multistep" 11 "github.com/mitchellh/packer/builder/azure/common/constants" 12 "github.com/mitchellh/packer/packer" 13 ) 14 15 type StepCreateResourceGroup struct { 16 client *AzureClient 17 create func(resourceGroupName string, location string) error 18 say func(message string) 19 error func(e error) 20 } 21 22 func NewStepCreateResourceGroup(client *AzureClient, ui packer.Ui) *StepCreateResourceGroup { 23 var step = &StepCreateResourceGroup{ 24 client: client, 25 say: func(message string) { ui.Say(message) }, 26 error: func(e error) { ui.Error(e.Error()) }, 27 } 28 29 step.create = step.createResourceGroup 30 return step 31 } 32 33 func (s *StepCreateResourceGroup) createResourceGroup(resourceGroupName string, location string) error { 34 _, err := s.client.GroupsClient.CreateOrUpdate(resourceGroupName, resources.ResourceGroup{ 35 Location: &location, 36 }) 37 38 return err 39 } 40 41 func (s *StepCreateResourceGroup) Run(state multistep.StateBag) multistep.StepAction { 42 s.say("Creating resource group ...") 43 44 var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string) 45 var location = state.Get(constants.ArmLocation).(string) 46 47 s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName)) 48 s.say(fmt.Sprintf(" -> Location : '%s'", location)) 49 50 err := s.create(resourceGroupName, location) 51 if err != nil { 52 state.Put(constants.Error, err) 53 s.error(err) 54 55 return multistep.ActionHalt 56 } 57 58 return multistep.ActionContinue 59 } 60 61 func (*StepCreateResourceGroup) Cleanup(multistep.StateBag) { 62 }