also use waiter code for spot instances
This commit is contained in:
parent
9e61005f7c
commit
dada63801b
|
@ -231,21 +231,26 @@ func (s *StepRunSpotInstance) Run(state multistep.StateBag) multistep.StepAction
|
||||||
|
|
||||||
ui.Message(fmt.Sprintf("Instance ID: %s", instanceId))
|
ui.Message(fmt.Sprintf("Instance ID: %s", instanceId))
|
||||||
ui.Say(fmt.Sprintf("Waiting for instance (%v) to become ready...", instanceId))
|
ui.Say(fmt.Sprintf("Waiting for instance (%v) to become ready...", instanceId))
|
||||||
stateChangeSpot := StateChangeConf{
|
describeInstanceStatus := &ec2.DescribeInstanceStatusInput{
|
||||||
Pending: []string{"pending"},
|
InstanceIds: []*string{aws.String(instanceId)},
|
||||||
Target: "running",
|
|
||||||
Refresh: InstanceStateRefreshFunc(ec2conn, instanceId),
|
|
||||||
StepState: state,
|
|
||||||
}
|
}
|
||||||
latestInstance, err := WaitForState(&stateChangeSpot)
|
if err := ec2conn.WaitUntilInstanceStatusOk(describeInstanceStatus); err != nil {
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("Error waiting for instance (%s) to become ready: %s", instanceId, err)
|
err := fmt.Errorf("Error waiting for instance (%s) to become ready: %s", instanceId, err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := latestInstance.(*ec2.Instance)
|
r, err := ec2conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
||||||
|
InstanceIds: []*string{aws.String(instanceId)},
|
||||||
|
})
|
||||||
|
if err != nil || len(r.Reservations) == 0 || len(r.Reservations[0].Instances) == 0 {
|
||||||
|
err := fmt.Errorf("Error finding source instance.")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
instance := r.Reservations[0].Instances[0]
|
||||||
|
|
||||||
// Retry creating tags for about 2.5 minutes
|
// Retry creating tags for about 2.5 minutes
|
||||||
err = retry.Retry(0.2, 30, 11, func(_ uint) (bool, error) {
|
err = retry.Retry(0.2, 30, 11, func(_ uint) (bool, error) {
|
||||||
|
|
Loading…
Reference in New Issue