Skip to content

Commit

Permalink
providers/aws: internetgateway timing tweaks
Browse files Browse the repository at this point in the history
So I think the AWS API is just broken here. In the case that the state
doesn't update, just assume it did after 5 seconds.
  • Loading branch information
mitchellh committed Jul 10, 2014
1 parent af776da commit 71b30c6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions builtin/providers/aws/resource_aws_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func resource_aws_internet_gateway_attach(
stateConf := &resource.StateChangeConf{
Pending: []string{"detached", "attaching"},
Target: "available",
Refresh: IGAttachStateRefreshFunc(ec2conn, s.ID),
Refresh: IGAttachStateRefreshFunc(ec2conn, s.ID, "available"),
Timeout: 1 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
Expand Down Expand Up @@ -209,7 +209,7 @@ func resource_aws_internet_gateway_detach(
stateConf := &resource.StateChangeConf{
Pending: []string{"attached", "detaching", "available"},
Target: "detached",
Refresh: IGAttachStateRefreshFunc(ec2conn, s.ID),
Refresh: IGAttachStateRefreshFunc(ec2conn, s.ID, "detached"),
Timeout: 1 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
Expand Down Expand Up @@ -262,8 +262,13 @@ func IGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {

// IGAttachStateRefreshFunc returns a resource.StateRefreshFunc that is used
// watch the state of an internet gateway's attachment.
func IGAttachStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
func IGAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) resource.StateRefreshFunc {
var start time.Time
return func() (interface{}, string, error) {
if start.IsZero() {
start = time.Now()
}

resp, err := conn.DescribeInternetGateways([]string{id}, ec2.NewFilter())
if err != nil {
ec2err, ok := err.(*ec2.Error)
Expand All @@ -283,6 +288,10 @@ func IGAttachStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFun

ig := &resp.InternetGateways[0]

if time.Now().Sub(start) > 5 * time.Second {
return ig, expected, nil
}

if len(ig.Attachments) == 0 {
// No attachments, we're detached
return ig, "detached", nil
Expand Down

0 comments on commit 71b30c6

Please sign in to comment.