resources: aws: ec2: CheckApply fix pending and stopping cases
If CheckApply was called when the instance was pending or stopping, it would return an error. This patch supresses these errors and tells the engine that the state can't yet be changed.
This commit is contained in:
committed by
James Shubin
parent
e330ebc8c9
commit
08e7caea6b
@@ -92,6 +92,9 @@ const (
|
||||
CweTargetJSON = "$.detail"
|
||||
// waitTimeout is the duration in seconds of the timeout context in CheckApply.
|
||||
waitTimeout = 400
|
||||
// AwsErrIncorrectInstanceState is the error returned when an action
|
||||
// cannot be completed due to the current instance state.
|
||||
AwsErrIncorrectInstanceState = "IncorrectInstanceState"
|
||||
)
|
||||
|
||||
//go:generate stringer -type=awsEc2Event -output=awsec2event_stringer.go
|
||||
@@ -798,6 +801,13 @@ func (obj *AwsEc2Res) CheckApply(apply bool) (checkOK bool, err error) {
|
||||
}
|
||||
_, err := obj.client.StartInstances(startInput)
|
||||
if err != nil {
|
||||
// If the instance is not in a state where it
|
||||
// can be started, we can't do anything.
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
if aerr.Code() == AwsErrIncorrectInstanceState {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return false, errwrap.Wrapf(err, "error starting instance")
|
||||
}
|
||||
if err := obj.client.WaitUntilInstanceRunningWithContext(ctx, describeInput); err != nil {
|
||||
@@ -816,6 +826,13 @@ func (obj *AwsEc2Res) CheckApply(apply bool) (checkOK bool, err error) {
|
||||
}
|
||||
_, err := obj.client.StopInstances(stopInput)
|
||||
if err != nil {
|
||||
// If the instance is not in a state where it
|
||||
// can be stopped, we can't do anything.
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
if aerr.Code() == AwsErrIncorrectInstanceState {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return false, errwrap.Wrapf(err, "error stopping instance")
|
||||
}
|
||||
if err := obj.client.WaitUntilInstanceStoppedWithContext(ctx, describeInput); err != nil {
|
||||
@@ -834,6 +851,13 @@ func (obj *AwsEc2Res) CheckApply(apply bool) (checkOK bool, err error) {
|
||||
}
|
||||
_, err := obj.client.TerminateInstances(terminateInput)
|
||||
if err != nil {
|
||||
// If the instance is not in a state where it
|
||||
// can be terminated, we can't do anything.
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
if aerr.Code() == "IncorrectInstanceState" {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return false, errwrap.Wrapf(err, "error terminating instance")
|
||||
}
|
||||
if err := obj.client.WaitUntilInstanceTerminatedWithContext(ctx, describeInput); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user