From 5d12c79d900157a7ecb008e5eeb929c821891ea1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 6 May 2015 11:09:51 -0700 Subject: [PATCH] provider/aws: retry VGW connection a bit due to eventual consistency --- .../providers/aws/resource_aws_route_table.go | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index 0c2190ec3..402db8068 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -210,11 +210,26 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error for _, vgw := range add { id := vgw.(string) - log.Printf("[INFO] Enabling VGW propagation for %s: %s", d.Id(), id) - _, err := conn.EnableVGWRoutePropagation(&ec2.EnableVGWRoutePropagationInput{ - RouteTableID: aws.String(d.Id()), - GatewayID: aws.String(id), - }) + var err error + for i := 0; i < 5; i++ { + log.Printf("[INFO] Enabling VGW propagation for %s: %s", d.Id(), id) + _, err = conn.EnableVGWRoutePropagation(&ec2.EnableVGWRoutePropagationInput{ + RouteTableID: aws.String(d.Id()), + GatewayID: aws.String(id), + }) + if err == nil { + break + } + + // If we get a Gateway.NotAttached, it is usually some + // eventually consistency stuff. So we have to just wait a + // bit... + ec2err, ok := err.(aws.APIError) + if ok && ec2err.Code == "Gateway.NotAttached" { + time.Sleep(20 * time.Second) + continue + } + } if err != nil { return err }