Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final retries after internet gateway timeouts #9779

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions aws/resource_aws_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{})
ig := *resp.InternetGateway
d.SetId(*ig.InternetGatewayId)
log.Printf("[INFO] InternetGateway ID: %s", d.Id())

var igRaw interface{}
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
igRaw, _, err := IGStateRefreshFunc(conn, d.Id())()
igRaw, _, err = IGStateRefreshFunc(conn, d.Id())()
if igRaw != nil {
return nil
}
Expand All @@ -63,9 +63,14 @@ func resourceAwsInternetGatewayCreate(d *schema.ResourceData, meta interface{})
return resource.NonRetryableError(err)
}
})

if isResourceTimeoutError(err) {
igRaw, _, err = IGStateRefreshFunc(conn, d.Id())()
if igRaw == nil {
return fmt.Errorf("error finding Internet Gateway (%s) after creation; retry running Terraform", d.Id())
}
}
if err != nil {
return fmt.Errorf("%s", err)
return fmt.Errorf("Error refreshing internet gateway state: %s", err)
}

err = setTags(conn, d)
Expand Down Expand Up @@ -142,29 +147,32 @@ func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{})
}

log.Printf("[INFO] Deleting Internet Gateway: %s", d.Id())

return resource.Retry(10*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteInternetGateway(&ec2.DeleteInternetGatewayInput{
InternetGatewayId: aws.String(d.Id()),
})
input := &ec2.DeleteInternetGatewayInput{
InternetGatewayId: aws.String(d.Id()),
}
err := resource.Retry(10*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteInternetGateway(input)
if err == nil {
return nil
}

ec2err, ok := err.(awserr.Error)
if !ok {
return resource.RetryableError(err)
if isAWSErr(err, "InvalidInternetGatewayID.NotFound", "") {
return nil
}

switch ec2err.Code() {
case "InvalidInternetGatewayID.NotFound":
return nil
case "DependencyViolation":
return resource.RetryableError(err) // retry
if isAWSErr(err, "DependencyViolation", "") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.DeleteInternetGateway(input)
}
if err != nil {
return fmt.Errorf("Error deleting internet gateway: %s", err)
}
return nil
}

func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{}) error {
Expand All @@ -181,25 +189,26 @@ func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{})
"[INFO] Attaching Internet Gateway '%s' to VPC '%s'",
d.Id(),
d.Get("vpc_id").(string))

input := &ec2.AttachInternetGatewayInput{
InternetGatewayId: aws.String(d.Id()),
VpcId: aws.String(d.Get("vpc_id").(string)),
}
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
_, err := conn.AttachInternetGateway(&ec2.AttachInternetGatewayInput{
InternetGatewayId: aws.String(d.Id()),
VpcId: aws.String(d.Get("vpc_id").(string)),
})
_, err := conn.AttachInternetGateway(input)
if err == nil {
return nil
}
if ec2err, ok := err.(awserr.Error); ok {
switch ec2err.Code() {
case "InvalidInternetGatewayID.NotFound":
return resource.RetryableError(err) // retry
}
if isAWSErr(err, "InvalidInternetGatewayID.NotFound", "") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.AttachInternetGateway(input)
}
if err != nil {
return err
return fmt.Errorf("Error attaching internet gateway: %s", err)
}

// A note on the states below: the AWS docs (as of July, 2014) say
Expand Down