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

vpc: Problem creating multiple managed prefix list entries #25046

Merged
merged 4 commits into from
Jun 13, 2022

Conversation

YakDriver
Copy link
Member

@YakDriver YakDriver commented May 25, 2022

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 #21835

Seems like this should be straightforward but now it's giving a new error. Anyone have thoughts?

Output from acceptance testing:

% make testacc TESTS=TestAccVPCManagedPrefixListEntry_ipv4Multiple PKG=ec2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccVPCManagedPrefixListEntry_ipv4Multiple'  -timeout 180m
=== RUN   TestAccVPCManagedPrefixListEntry_ipv4Multiple
=== PAUSE TestAccVPCManagedPrefixListEntry_ipv4Multiple
=== CONT  TestAccVPCManagedPrefixListEntry_ipv4Multiple
    vpc_managed_prefix_list_entry_test.go:56: Step 1/1 error: Error running apply: exit status 1
        
        Error: error creating EC2 Managed Prefix List Entry (pl-0a58f0e9573b85871,10.0.1.0/24): PrefixListVersionMismatch: The prefix list has the incorrect version number.
        	status code: 400, request id: 7b4c13b8-9faf-45ba-9164-ff79958af14b
        
          with aws_ec2_managed_prefix_list_entry.test2,
          on terraform_plugin_test.tf line 14, in resource "aws_ec2_managed_prefix_list_entry" "test2":
          14: resource "aws_ec2_managed_prefix_list_entry" "test2" {
        
        
        Error: error creating EC2 Managed Prefix List Entry (pl-0a58f0e9573b85871,10.0.2.0/24): PrefixListVersionMismatch: The prefix list has the incorrect version number.
        	status code: 400, request id: c786e1e0-dfbb-4ed8-ac37-5d7774de506c
        
          with aws_ec2_managed_prefix_list_entry.test3,
          on terraform_plugin_test.tf line 20, in resource "aws_ec2_managed_prefix_list_entry" "test3":
          20: resource "aws_ec2_managed_prefix_list_entry" "test3" {
        
--- FAIL: TestAccVPCManagedPrefixListEntry_ipv4Multiple (19.06s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	20.708s

@YakDriver YakDriver marked this pull request as draft May 25, 2022 18:45
@YakDriver YakDriver changed the title vpc: Create problem with managed prefix list entry vpc: Problem creating multiple managed prefix list entries May 25, 2022
@github-actions github-actions bot added service/vpc Issues and PRs that pertain to the vpc service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/M Managed by automation to categorize the size of a PR. labels May 25, 2022
@windowlistener
Copy link

Hi,
I tried moving FindManagedPrefixByID(conn,plID) inside the retry function, and it seems to work fine. The ModifyManagedPrefixListInput requires a CurrentVersion parameter that changes each time the prefix list is modified, this is the cause of the error.

_, err := tfresource.RetryWhenAWSErrCodeEquals(d.Timeout(schema.TimeoutCreate), func() (interface{}, error) {
	
	pl, err := FindManagedPrefixListByID(conn, plID)

	if err != nil {
		return nil, fmt.Errorf("error reading EC2 Managed Prefix List (%s): %w", plID, err)
	}

	input := &ec2.ModifyManagedPrefixListInput{
		AddEntries:     []*ec2.AddPrefixListEntry{addPrefixListEntry},
		CurrentVersion: pl.Version,
		PrefixListId:   aws.String(plID),
	}

	return conn.ModifyManagedPrefixList(input)
}, "IncorrectState","PrefixListVersionMismatch")

@taliesins
Copy link

Feels like we should add in in a mutex which locks on plID just before we find the managed prefix list by id. Would be more graceful for large prefix lists.

Something like:
https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/conns/mutexkv.go

@YakDriver YakDriver force-pushed the b-managed-prefix-list-entry-retry branch from 8b1da87 to c1c13cd Compare June 13, 2022 15:20
@YakDriver YakDriver marked this pull request as ready for review June 13, 2022 15:21
@YakDriver
Copy link
Member Author

@windowlistener @taliesins Huge thanks for your thoughts! I've updated the PR with mutexes and better retry logic for both create and delete. I think 🤞 this should resolve the issue. The test works well at the very least.

@YakDriver YakDriver merged commit 203b8d7 into main Jun 13, 2022
@YakDriver YakDriver deleted the b-managed-prefix-list-entry-retry branch June 13, 2022 16:40
@github-actions github-actions bot added this to the v4.19.0 milestone Jun 13, 2022
github-actions bot pushed a commit that referenced this pull request Jun 13, 2022
@github-actions
Copy link

This functionality has been released in v4.19.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. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/vpc Issues and PRs that pertain to the vpc service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple aws_ec2_managed_prefix_list_entry resources fail to create
3 participants