github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/alicloud/ecs/step_config_public_ip.go (about) 1 package ecs 2 3 import ( 4 "fmt" 5 6 "github.com/denverdino/aliyungo/ecs" 7 "github.com/hashicorp/packer/packer" 8 "github.com/mitchellh/multistep" 9 ) 10 11 type stepConfigAlicloudPublicIP struct { 12 publicIPAdress string 13 RegionId string 14 } 15 16 func (s *stepConfigAlicloudPublicIP) Run(state multistep.StateBag) multistep.StepAction { 17 client := state.Get("client").(*ecs.Client) 18 ui := state.Get("ui").(packer.Ui) 19 instance := state.Get("instance").(*ecs.InstanceAttributesType) 20 21 ipaddress, err := client.AllocatePublicIpAddress(instance.InstanceId) 22 if err != nil { 23 state.Put("error", err) 24 ui.Say(fmt.Sprintf("Error allocating public ip: %s", err)) 25 return multistep.ActionHalt 26 } 27 s.publicIPAdress = ipaddress 28 ui.Say(fmt.Sprintf("Allocated public ip address %s.", ipaddress)) 29 state.Put("ipaddress", ipaddress) 30 return multistep.ActionContinue 31 } 32 33 func (s *stepConfigAlicloudPublicIP) Cleanup(state multistep.StateBag) { 34 35 }