-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathwaiter.go
44 lines (36 loc) · 1.36 KB
/
waiter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package waiter
import (
"time"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
const (
// Maximum amount of time to wait for an InstanceRefresh to be started
// Must be at least as long as InstanceRefreshCancelledTimeout, since we try to cancel any
// existing Instance Refreshes when starting.
InstanceRefreshStartedTimeout = InstanceRefreshCancelledTimeout
// Maximum amount of time to wait for an Instance Refresh to be Cancelled
InstanceRefreshCancelledTimeout = 15 * time.Minute
)
func InstanceRefreshCancelled(conn *autoscaling.AutoScaling, asgName, instanceRefreshId string) (*autoscaling.InstanceRefresh, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
autoscaling.InstanceRefreshStatusPending,
autoscaling.InstanceRefreshStatusInProgress,
autoscaling.InstanceRefreshStatusCancelling,
},
Target: []string{
autoscaling.InstanceRefreshStatusCancelled,
// Failed and Successful are also acceptable end-states
autoscaling.InstanceRefreshStatusFailed,
autoscaling.InstanceRefreshStatusSuccessful,
},
Refresh: InstanceRefreshStatus(conn, asgName, instanceRefreshId),
Timeout: InstanceRefreshCancelledTimeout,
}
outputRaw, err := stateConf.WaitForState()
if v, ok := outputRaw.(*autoscaling.InstanceRefresh); ok {
return v, err
}
return nil, err
}