2013-07-20 22:58:27 -04:00
|
|
|
package common
|
2013-05-21 03:55:32 -04:00
|
|
|
|
|
|
|
import (
|
2015-06-14 02:12:59 -04:00
|
|
|
"encoding/base64"
|
2013-06-11 17:15:43 -04:00
|
|
|
"fmt"
|
2014-09-06 13:44:12 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2015-06-03 17:13:52 -04:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2015-04-05 17:58:48 -04:00
|
|
|
|
2013-06-04 13:00:06 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2013-05-21 03:55:32 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
2013-07-20 22:58:27 -04:00
|
|
|
type StepRunSourceInstance struct {
|
2013-12-27 22:54:35 -05:00
|
|
|
AssociatePublicIpAddress bool
|
|
|
|
AvailabilityZone string
|
|
|
|
BlockDevices BlockDevices
|
2013-11-25 20:32:08 -05:00
|
|
|
Debug bool
|
2015-10-06 16:36:21 -04:00
|
|
|
EbsOptimized bool
|
2013-11-25 20:32:08 -05:00
|
|
|
ExpectedRootDevice string
|
|
|
|
InstanceType string
|
|
|
|
IamInstanceProfile string
|
2013-12-27 22:54:35 -05:00
|
|
|
SourceAMI string
|
2014-09-06 13:44:12 -04:00
|
|
|
SpotPrice string
|
|
|
|
SpotPriceProduct string
|
2013-11-25 20:32:08 -05:00
|
|
|
SubnetId string
|
2013-12-27 22:54:35 -05:00
|
|
|
Tags map[string]string
|
|
|
|
UserData string
|
|
|
|
UserDataFile string
|
2014-09-06 13:44:12 -04:00
|
|
|
|
2015-07-07 13:07:38 -04:00
|
|
|
instanceId string
|
2015-04-05 17:58:48 -04:00
|
|
|
spotRequest *ec2.SpotInstanceRequest
|
2013-05-21 03:55:32 -04:00
|
|
|
}
|
|
|
|
|
2013-08-31 15:58:55 -04:00
|
|
|
func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
ec2conn := state.Get("ec2").(*ec2.EC2)
|
|
|
|
keyName := state.Get("keyPair").(string)
|
2015-04-05 17:58:48 -04:00
|
|
|
tempSecurityGroupIds := state.Get("securityGroupIds").([]string)
|
2013-08-31 15:58:55 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-05-21 03:55:32 -04:00
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
securityGroupIds := make([]*string, len(tempSecurityGroupIds))
|
|
|
|
for i, sg := range tempSecurityGroupIds {
|
2015-07-02 10:23:44 -04:00
|
|
|
securityGroupIds[i] = aws.String(sg)
|
2015-04-05 17:58:48 -04:00
|
|
|
}
|
|
|
|
|
2013-08-12 14:52:43 -04:00
|
|
|
userData := s.UserData
|
|
|
|
if s.UserDataFile != "" {
|
|
|
|
contents, err := ioutil.ReadFile(s.UserDataFile)
|
|
|
|
if err != nil {
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", fmt.Errorf("Problem reading user data file: %s", err))
|
2013-08-12 14:52:43 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2015-06-14 02:12:59 -04:00
|
|
|
// Test if it is encoded already, and if not, encode it
|
|
|
|
if _, err := base64.StdEncoding.DecodeString(string(contents)); err != nil {
|
|
|
|
log.Printf("[DEBUG] base64 encoding user data...")
|
|
|
|
contents = []byte(base64.StdEncoding.EncodeToString(contents))
|
|
|
|
}
|
|
|
|
|
2013-08-12 14:52:43 -04:00
|
|
|
userData = string(contents)
|
2015-06-14 02:12:59 -04:00
|
|
|
|
2013-08-12 14:52:43 -04:00
|
|
|
}
|
|
|
|
|
2013-05-21 03:55:32 -04:00
|
|
|
ui.Say("Launching a source AWS instance...")
|
2015-04-05 17:58:48 -04:00
|
|
|
imageResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{
|
2015-08-17 20:44:01 -04:00
|
|
|
ImageIds: []*string{&s.SourceAMI},
|
2015-04-05 17:58:48 -04:00
|
|
|
})
|
2013-07-11 18:01:23 -04:00
|
|
|
if err != nil {
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", fmt.Errorf("There was a problem with the source AMI: %s", err))
|
2013-07-11 18:01:23 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2013-07-31 18:29:03 -04:00
|
|
|
|
2013-07-31 17:20:25 -04:00
|
|
|
if len(imageResp.Images) != 1 {
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", fmt.Errorf("The source AMI '%s' could not be found.", s.SourceAMI))
|
2013-07-31 17:20:25 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2013-07-11 18:01:23 -04:00
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
if s.ExpectedRootDevice != "" && *imageResp.Images[0].RootDeviceType != s.ExpectedRootDevice {
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", fmt.Errorf(
|
2013-07-20 22:58:27 -04:00
|
|
|
"The provided source AMI has an invalid root device type.\n"+
|
|
|
|
"Expected '%s', got '%s'.",
|
2015-04-05 17:58:48 -04:00
|
|
|
s.ExpectedRootDevice, *imageResp.Images[0].RootDeviceType))
|
2013-07-11 18:01:23 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-09-06 13:44:12 -04:00
|
|
|
spotPrice := s.SpotPrice
|
2015-04-03 20:52:54 -04:00
|
|
|
availabilityZone := s.AvailabilityZone
|
2014-09-06 13:44:12 -04:00
|
|
|
if spotPrice == "auto" {
|
|
|
|
ui.Message(fmt.Sprintf(
|
|
|
|
"Finding spot price for %s %s...",
|
|
|
|
s.SpotPriceProduct, s.InstanceType))
|
|
|
|
|
|
|
|
// Detect the spot price
|
|
|
|
startTime := time.Now().Add(-1 * time.Hour)
|
2015-04-05 17:58:48 -04:00
|
|
|
resp, err := ec2conn.DescribeSpotPriceHistory(&ec2.DescribeSpotPriceHistoryInput{
|
|
|
|
InstanceTypes: []*string{&s.InstanceType},
|
|
|
|
ProductDescriptions: []*string{&s.SpotPriceProduct},
|
|
|
|
AvailabilityZone: &s.AvailabilityZone,
|
|
|
|
StartTime: &startTime,
|
2014-09-06 13:44:12 -04:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error finding spot price: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
var price float64
|
2015-04-05 17:58:48 -04:00
|
|
|
for _, history := range resp.SpotPriceHistory {
|
|
|
|
log.Printf("[INFO] Candidate spot price: %s", *history.SpotPrice)
|
|
|
|
current, err := strconv.ParseFloat(*history.SpotPrice, 64)
|
2014-09-06 13:44:12 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("[ERR] Error parsing spot price: %s", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if price == 0 || current < price {
|
|
|
|
price = current
|
2015-04-03 20:52:54 -04:00
|
|
|
if s.AvailabilityZone == "" {
|
2015-05-28 12:44:33 -04:00
|
|
|
availabilityZone = *history.AvailabilityZone
|
2015-04-03 20:52:54 -04:00
|
|
|
}
|
2014-09-06 13:44:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if price == 0 {
|
|
|
|
err := fmt.Errorf("No candidate spot prices found!")
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
spotPrice = strconv.FormatFloat(price, 'f', -1, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
var instanceId string
|
|
|
|
|
2015-10-06 17:13:17 -04:00
|
|
|
if spotPrice == "" || spotPrice == "0" {
|
2015-04-05 17:58:48 -04:00
|
|
|
runOpts := &ec2.RunInstancesInput{
|
|
|
|
KeyName: &keyName,
|
2015-08-17 20:44:01 -04:00
|
|
|
ImageId: &s.SourceAMI,
|
2015-04-05 17:58:48 -04:00
|
|
|
InstanceType: &s.InstanceType,
|
|
|
|
UserData: &userData,
|
2015-07-28 20:10:21 -04:00
|
|
|
MaxCount: aws.Int64(1),
|
|
|
|
MinCount: aws.Int64(1),
|
2015-08-17 20:44:01 -04:00
|
|
|
IamInstanceProfile: &ec2.IamInstanceProfileSpecification{Name: &s.IamInstanceProfile},
|
2015-04-05 17:58:48 -04:00
|
|
|
BlockDeviceMappings: s.BlockDevices.BuildLaunchDevices(),
|
|
|
|
Placement: &ec2.Placement{AvailabilityZone: &s.AvailabilityZone},
|
2015-10-18 14:37:14 -04:00
|
|
|
EbsOptimized: &s.EbsOptimized,
|
2015-04-05 17:58:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if s.SubnetId != "" && s.AssociatePublicIpAddress {
|
|
|
|
runOpts.NetworkInterfaces = []*ec2.InstanceNetworkInterfaceSpecification{
|
|
|
|
&ec2.InstanceNetworkInterfaceSpecification{
|
2015-07-28 20:10:21 -04:00
|
|
|
DeviceIndex: aws.Int64(0),
|
2015-08-17 20:44:01 -04:00
|
|
|
AssociatePublicIpAddress: &s.AssociatePublicIpAddress,
|
|
|
|
SubnetId: &s.SubnetId,
|
2015-04-05 17:58:48 -04:00
|
|
|
Groups: securityGroupIds,
|
2015-07-28 20:10:21 -04:00
|
|
|
DeleteOnTermination: aws.Bool(true),
|
2015-04-05 17:58:48 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
2015-08-17 20:44:01 -04:00
|
|
|
runOpts.SubnetId = &s.SubnetId
|
|
|
|
runOpts.SecurityGroupIds = securityGroupIds
|
2014-05-07 13:13:27 -04:00
|
|
|
}
|
2015-04-05 17:58:48 -04:00
|
|
|
|
2014-05-07 13:13:27 -04:00
|
|
|
runResp, err := ec2conn.RunInstances(runOpts)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error launching source instance: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2015-08-17 20:44:01 -04:00
|
|
|
instanceId = *runResp.Instances[0].InstanceId
|
2014-05-07 13:13:27 -04:00
|
|
|
} else {
|
2014-09-05 19:58:17 -04:00
|
|
|
ui.Message(fmt.Sprintf(
|
|
|
|
"Requesting spot instance '%s' for: %s",
|
2014-09-06 13:44:12 -04:00
|
|
|
s.InstanceType, spotPrice))
|
2015-04-05 17:58:48 -04:00
|
|
|
runSpotResp, err := ec2conn.RequestSpotInstances(&ec2.RequestSpotInstancesInput{
|
|
|
|
SpotPrice: &spotPrice,
|
|
|
|
LaunchSpecification: &ec2.RequestSpotLaunchSpecification{
|
|
|
|
KeyName: &keyName,
|
2015-08-17 20:44:01 -04:00
|
|
|
ImageId: &s.SourceAMI,
|
2015-04-05 17:58:48 -04:00
|
|
|
InstanceType: &s.InstanceType,
|
|
|
|
UserData: &userData,
|
2015-08-17 20:44:01 -04:00
|
|
|
IamInstanceProfile: &ec2.IamInstanceProfileSpecification{Name: &s.IamInstanceProfile},
|
2015-04-05 17:58:48 -04:00
|
|
|
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
|
2015-06-14 11:35:50 -04:00
|
|
|
&ec2.InstanceNetworkInterfaceSpecification{
|
2015-07-28 20:10:21 -04:00
|
|
|
DeviceIndex: aws.Int64(0),
|
2015-08-17 20:44:01 -04:00
|
|
|
AssociatePublicIpAddress: &s.AssociatePublicIpAddress,
|
|
|
|
SubnetId: &s.SubnetId,
|
2015-06-14 11:35:50 -04:00
|
|
|
Groups: securityGroupIds,
|
2015-07-28 20:10:21 -04:00
|
|
|
DeleteOnTermination: aws.Bool(true),
|
2015-06-14 11:35:50 -04:00
|
|
|
},
|
2015-04-05 17:58:48 -04:00
|
|
|
},
|
2015-05-28 12:35:02 -04:00
|
|
|
Placement: &ec2.SpotPlacement{
|
|
|
|
AvailabilityZone: &availabilityZone,
|
|
|
|
},
|
2015-04-05 17:58:48 -04:00
|
|
|
BlockDeviceMappings: s.BlockDevices.BuildLaunchDevices(),
|
2015-10-18 14:37:14 -04:00
|
|
|
EbsOptimized: &s.EbsOptimized,
|
2015-04-05 17:58:48 -04:00
|
|
|
},
|
|
|
|
})
|
2014-05-07 13:13:27 -04:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error launching source spot instance: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-09-05 19:58:17 -04:00
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
s.spotRequest = runSpotResp.SpotInstanceRequests[0]
|
2014-09-05 19:58:17 -04:00
|
|
|
|
2015-08-17 20:44:01 -04:00
|
|
|
spotRequestId := s.spotRequest.SpotInstanceRequestId
|
2015-04-05 17:58:48 -04:00
|
|
|
ui.Message(fmt.Sprintf("Waiting for spot request (%s) to become active...", *spotRequestId))
|
2014-05-07 13:13:27 -04:00
|
|
|
stateChange := StateChangeConf{
|
|
|
|
Pending: []string{"open"},
|
|
|
|
Target: "active",
|
2015-04-05 17:58:48 -04:00
|
|
|
Refresh: SpotRequestStateRefreshFunc(ec2conn, *spotRequestId),
|
2014-05-07 13:13:27 -04:00
|
|
|
StepState: state,
|
|
|
|
}
|
|
|
|
_, err = WaitForState(&stateChange)
|
|
|
|
if err != nil {
|
2015-04-05 17:58:48 -04:00
|
|
|
err := fmt.Errorf("Error waiting for spot request (%s) to become ready: %s", *spotRequestId, err)
|
2014-05-07 13:13:27 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2015-04-05 17:58:48 -04:00
|
|
|
|
|
|
|
spotResp, err := ec2conn.DescribeSpotInstanceRequests(&ec2.DescribeSpotInstanceRequestsInput{
|
2015-08-17 20:44:01 -04:00
|
|
|
SpotInstanceRequestIds: []*string{spotRequestId},
|
2015-04-05 17:58:48 -04:00
|
|
|
})
|
2014-05-07 13:13:27 -04:00
|
|
|
if err != nil {
|
2015-04-05 17:58:48 -04:00
|
|
|
err := fmt.Errorf("Error finding spot request (%s): %s", *spotRequestId, err)
|
2014-05-07 13:13:27 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2015-08-17 20:44:01 -04:00
|
|
|
instanceId = *spotResp.SpotInstanceRequests[0].InstanceId
|
2014-05-07 13:13:27 -04:00
|
|
|
}
|
|
|
|
|
2015-07-07 13:07:38 -04:00
|
|
|
// Set the instance ID so that the cleanup works properly
|
|
|
|
s.instanceId = instanceId
|
|
|
|
|
2014-12-15 20:18:47 -05:00
|
|
|
ui.Message(fmt.Sprintf("Instance ID: %s", instanceId))
|
|
|
|
ui.Say(fmt.Sprintf("Waiting for instance (%v) to become ready...", instanceId))
|
2013-07-25 21:49:15 -04:00
|
|
|
stateChange := StateChangeConf{
|
|
|
|
Pending: []string{"pending"},
|
|
|
|
Target: "running",
|
2014-12-15 20:18:47 -05:00
|
|
|
Refresh: InstanceStateRefreshFunc(ec2conn, instanceId),
|
2013-07-25 21:49:15 -04:00
|
|
|
StepState: state,
|
|
|
|
}
|
2013-07-29 21:47:43 -04:00
|
|
|
latestInstance, err := WaitForState(&stateChange)
|
2013-05-21 03:55:32 -04:00
|
|
|
if err != nil {
|
2015-06-15 12:53:21 -04:00
|
|
|
err := fmt.Errorf("Error waiting for instance (%s) to become ready: %s", instanceId, err)
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", err)
|
2013-05-21 03:55:32 -04:00
|
|
|
ui.Error(err.Error())
|
2013-06-04 13:00:06 -04:00
|
|
|
return multistep.ActionHalt
|
2013-05-21 03:55:32 -04:00
|
|
|
}
|
|
|
|
|
2015-07-07 13:07:38 -04:00
|
|
|
instance := latestInstance.(*ec2.Instance)
|
2013-08-30 17:55:56 -04:00
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
ec2Tags := make([]*ec2.Tag, 1, len(s.Tags)+1)
|
|
|
|
ec2Tags[0] = &ec2.Tag{Key: aws.String("Name"), Value: aws.String("Packer Builder")}
|
2014-09-04 21:43:35 -04:00
|
|
|
for k, v := range s.Tags {
|
2015-06-25 11:02:38 -04:00
|
|
|
ec2Tags = append(ec2Tags, &ec2.Tag{Key: aws.String(k), Value: aws.String(v)})
|
2014-09-04 21:43:35 -04:00
|
|
|
}
|
|
|
|
|
2015-04-05 17:58:48 -04:00
|
|
|
_, err = ec2conn.CreateTags(&ec2.CreateTagsInput{
|
|
|
|
Tags: ec2Tags,
|
2015-08-17 20:44:01 -04:00
|
|
|
Resources: []*string{instance.InstanceId},
|
2015-04-05 17:58:48 -04:00
|
|
|
})
|
2014-09-04 21:43:35 -04:00
|
|
|
if err != nil {
|
|
|
|
ui.Message(
|
|
|
|
fmt.Sprintf("Failed to tag a Name on the builder instance: %s", err))
|
|
|
|
}
|
|
|
|
|
2013-08-30 17:55:56 -04:00
|
|
|
if s.Debug {
|
2015-08-17 20:44:01 -04:00
|
|
|
if instance.PublicDnsName != nil && *instance.PublicDnsName != "" {
|
|
|
|
ui.Message(fmt.Sprintf("Public DNS: %s", *instance.PublicDnsName))
|
2013-08-30 17:55:56 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 20:44:01 -04:00
|
|
|
if instance.PublicIpAddress != nil && *instance.PublicIpAddress != "" {
|
|
|
|
ui.Message(fmt.Sprintf("Public IP: %s", *instance.PublicIpAddress))
|
2013-11-26 00:03:45 -05:00
|
|
|
}
|
|
|
|
|
2015-08-17 20:44:01 -04:00
|
|
|
if instance.PrivateIpAddress != nil && *instance.PrivateIpAddress != "" {
|
|
|
|
ui.Message(fmt.Sprintf("Private IP: %s", *instance.PrivateIpAddress))
|
2013-08-30 17:55:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 13:07:38 -04:00
|
|
|
state.Put("instance", instance)
|
2013-05-21 03:55:32 -04:00
|
|
|
|
2013-06-04 13:00:06 -04:00
|
|
|
return multistep.ActionContinue
|
2013-05-21 03:55:32 -04:00
|
|
|
}
|
|
|
|
|
2013-08-31 15:58:55 -04:00
|
|
|
func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) {
|
2013-05-21 03:55:32 -04:00
|
|
|
|
2013-08-31 15:58:55 -04:00
|
|
|
ec2conn := state.Get("ec2").(*ec2.EC2)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-05-21 03:55:32 -04:00
|
|
|
|
2014-05-10 12:51:35 -04:00
|
|
|
// Cancel the spot request if it exists
|
|
|
|
if s.spotRequest != nil {
|
|
|
|
ui.Say("Cancelling the spot request...")
|
2015-04-05 17:58:48 -04:00
|
|
|
input := &ec2.CancelSpotInstanceRequestsInput{
|
2015-08-17 20:44:01 -04:00
|
|
|
SpotInstanceRequestIds: []*string{s.spotRequest.SpotInstanceRequestId},
|
2015-04-05 17:58:48 -04:00
|
|
|
}
|
|
|
|
if _, err := ec2conn.CancelSpotInstanceRequests(input); err != nil {
|
2014-05-10 12:51:35 -04:00
|
|
|
ui.Error(fmt.Sprintf("Error cancelling the spot request, may still be around: %s", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
stateChange := StateChangeConf{
|
|
|
|
Pending: []string{"active", "open"},
|
2015-08-17 20:44:01 -04:00
|
|
|
Refresh: SpotRequestStateRefreshFunc(ec2conn, *s.spotRequest.SpotInstanceRequestId),
|
2014-05-10 12:51:35 -04:00
|
|
|
Target: "cancelled",
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitForState(&stateChange)
|
2013-06-27 21:42:07 -04:00
|
|
|
|
2013-07-25 21:49:15 -04:00
|
|
|
}
|
|
|
|
|
2014-05-10 12:51:35 -04:00
|
|
|
// Terminate the source instance if it exists
|
2015-07-07 13:07:38 -04:00
|
|
|
if s.instanceId != "" {
|
2014-05-10 12:51:35 -04:00
|
|
|
ui.Say("Terminating the source AWS instance...")
|
2015-08-17 20:44:01 -04:00
|
|
|
if _, err := ec2conn.TerminateInstances(&ec2.TerminateInstancesInput{InstanceIds: []*string{&s.instanceId}}); err != nil {
|
2014-05-10 12:51:35 -04:00
|
|
|
ui.Error(fmt.Sprintf("Error terminating instance, may still be around: %s", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
stateChange := StateChangeConf{
|
|
|
|
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
2015-07-07 13:07:38 -04:00
|
|
|
Refresh: InstanceStateRefreshFunc(ec2conn, s.instanceId),
|
2014-05-10 12:51:35 -04:00
|
|
|
Target: "terminated",
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitForState(&stateChange)
|
|
|
|
}
|
2013-05-21 03:55:32 -04:00
|
|
|
}
|