From 71b30c633f4824bba9c9a7eada788cd169db7568 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 10 Jul 2014 15:33:50 -0700 Subject: [PATCH] providers/aws: internetgateway timing tweaks 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. --- .../aws/resource_aws_internet_gateway.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_internet_gateway.go b/builtin/providers/aws/resource_aws_internet_gateway.go index 0c5283df7..964e6851f 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway.go +++ b/builtin/providers/aws/resource_aws_internet_gateway.go @@ -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 { @@ -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 { @@ -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) @@ -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