github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/alicloud/ecs/step_config_public_ip.go (about)

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