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

resource/aws_subnet: Handle read-after-create eventual consistency #18392

Merged
merged 2 commits into from
Mar 25, 2021

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Mar 24, 2021

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #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)

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)
```
@bflad bflad added the bug Addresses a defect in current functionality. label Mar 24, 2021
@bflad bflad requested a review from a team as a code owner March 24, 2021 20:59
@ghost ghost added size/S Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. labels Mar 24, 2021
@gdavison gdavison self-assigned this Mar 25, 2021
Copy link
Contributor

@gdavison gdavison left a 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)

Comment on lines +245 to +284
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
}
Copy link
Contributor

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.

Copy link
Contributor Author

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:

@bflad bflad merged commit 0016fc8 into main Mar 25, 2021
@bflad bflad deleted the b-aws_subnet-d.IsNewResource branch March 25, 2021 21:38
@github-actions github-actions bot added this to the v3.34.0 milestone Mar 25, 2021
github-actions bot pushed a commit that referenced this pull request Mar 25, 2021
@ghost
Copy link

ghost commented Mar 26, 2021

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!

@ghost
Copy link

ghost commented Apr 25, 2021

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!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

resource/aws_subnet: an unexpected new value for was present, but now absent.
2 participants