-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
resource/aws_subnet: Handle read-after-create eventual consistency #18392
Conversation
Reference: #12829 Reference: #16796 Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSSubnet_availabilityZoneId (53.74s) --- PASS: TestAccAWSSubnet_basic (52.50s) --- PASS: TestAccAWSSubnet_defaultAndIgnoreTags (80.26s) --- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_duplicateTag (6.45s) --- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_nonOverlappingTag (84.84s) --- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_overlappingTag (86.61s) --- PASS: TestAccAWSSubnet_defaultTags_providerOnly (87.99s) --- PASS: TestAccAWSSubnet_defaultTags_updateToProviderOnly (69.48s) --- PASS: TestAccAWSSubnet_defaultTags_updateToResourceOnly (72.12s) --- PASS: TestAccAWSSubnet_disappears (41.08s) --- PASS: TestAccAWSSubnet_enableIpv6 (109.36s) --- PASS: TestAccAWSSubnet_ignoreTags (81.13s) --- PASS: TestAccAWSSubnet_ipv6 (118.69s) --- PASS: TestAccAWSSubnet_MapPublicIpOnLaunch (118.55s) --- PASS: TestAccAWSSubnet_tags (106.25s) --- SKIP: TestAccAWSSubnet_CustomerOwnedIpv4Pool (1.44s) --- SKIP: TestAccAWSSubnet_MapCustomerOwnedIpOnLaunch (1.40s) --- SKIP: TestAccAWSSubnet_outpost (1.70s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- PASS: TestAccAWSSubnet_availabilityZoneId (55.41s) --- PASS: TestAccAWSSubnet_basic (55.46s) --- PASS: TestAccAWSSubnet_defaultAndIgnoreTags (85.95s) --- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_duplicateTag (6.64s) --- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_nonOverlappingTag (82.23s) --- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_overlappingTag (84.95s) --- PASS: TestAccAWSSubnet_defaultTags_providerOnly (86.26s) --- PASS: TestAccAWSSubnet_defaultTags_updateToProviderOnly (69.05s) --- PASS: TestAccAWSSubnet_defaultTags_updateToResourceOnly (73.74s) --- PASS: TestAccAWSSubnet_disappears (42.78s) --- PASS: TestAccAWSSubnet_enableIpv6 (117.40s) --- PASS: TestAccAWSSubnet_ignoreTags (83.74s) --- PASS: TestAccAWSSubnet_ipv6 (126.25s) --- PASS: TestAccAWSSubnet_MapPublicIpOnLaunch (124.27s) --- PASS: TestAccAWSSubnet_tags (115.31s) --- SKIP: TestAccAWSSubnet_CustomerOwnedIpv4Pool (6.95s) --- SKIP: TestAccAWSSubnet_MapCustomerOwnedIpOnLaunch (2.60s) --- SKIP: TestAccAWSSubnet_outpost (2.14s) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment on where to handle not found cases, otherwise LGTM 🚀
--- SKIP: TestAccAWSSubnet_outpost (1.17s)
--- SKIP: TestAccAWSSubnet_MapCustomerOwnedIpOnLaunch (1.29s)
--- SKIP: TestAccAWSSubnet_CustomerOwnedIpv4Pool (6.13s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_duplicateTag (9.25s)
--- PASS: TestAccAWSSubnet_disappears (46.97s)
--- PASS: TestAccAWSSubnet_availabilityZoneId (55.93s)
--- PASS: TestAccAWSSubnet_basic (56.90s)
--- PASS: TestAccAWSSubnet_defaultTags_updateToProviderOnly (75.08s)
--- PASS: TestAccAWSSubnet_defaultTags_updateToResourceOnly (78.74s)
--- PASS: TestAccAWSSubnet_defaultAndIgnoreTags (85.26s)
--- PASS: TestAccAWSSubnet_ignoreTags (85.50s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_nonOverlappingTag (89.09s)
--- PASS: TestAccAWSSubnet_defaultTags_providerOnly (90.52s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_overlappingTag (89.93s)
--- PASS: TestAccAWSSubnet_enableIpv6 (100.95s)
--- PASS: TestAccAWSSubnet_tags (101.94s)
--- PASS: TestAccAWSSubnet_ipv6 (102.25s)
--- PASS: TestAccAWSSubnet_MapPublicIpOnLaunch (111.12s)
if d.IsNewResource() && tfawserr.ErrCodeEquals(err, "InvalidSubnetID.NotFound") { | ||
return resource.RetryableError(err) | ||
} | ||
return err | ||
|
||
if err != nil { | ||
return resource.NonRetryableError(err) | ||
} | ||
|
||
if d.IsNewResource() && subnet == nil { | ||
return resource.RetryableError(&resource.NotFoundError{ | ||
LastError: fmt.Errorf("EC2 Subnet (%s) not found", d.Id()), | ||
}) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if tfresource.TimedOut(err) { | ||
subnet, err = finder.SubnetByID(conn, d.Id()) | ||
} | ||
if resp == nil { | ||
|
||
if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, "InvalidSubnetID.NotFound") { | ||
log.Printf("[WARN] EC2 Subnet (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
subnet := resp.Subnets[0] | ||
if err != nil { | ||
return fmt.Errorf("error reading EC2 Subnet (%s): %w", d.Id(), err) | ||
} | ||
|
||
if subnet == nil { | ||
if d.IsNewResource() { | ||
return fmt.Errorf("error reading EC2 Subnet (%s): not found after creation", d.Id()) | ||
} | ||
|
||
log.Printf("[WARN] EC2 Subnet (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If finder.SubnetByID()
returns a resource.NotFoundError
when the subnet is not found, we'd have to do a lot less checking for different not found cases at this level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this is likely a good move, but it is not the current standard, I am not immediately sure of all the implications, and I don't feel comfortable implementing it my own without discussing it first. I have created two tracking issues for following up to this:
This has been released in version 3.34.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Closes #12829
Reference: #16796
Output from acceptance testing in AWS Commercial:
Output from acceptance testing in AWS GovCloud (US):