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

r/aws_network_acl_rule: Prevent creation of duplicate Terraform resources #36324

Closed
ewbankkit opened this issue Mar 12, 2024 · 6 comments · Fixed by #36326
Closed

r/aws_network_acl_rule: Prevent creation of duplicate Terraform resources #36324

ewbankkit opened this issue Mar 12, 2024 · 6 comments · Fixed by #36326
Labels
bug Addresses a defect in current functionality. service/vpc Issues and PRs that pertain to the vpc service.
Milestone

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented Mar 12, 2024

Define multiple ACL rules with identical attributes but different Terraform resource names.
Example:

resource "aws_network_acl_rule" "original-rule" {
  network_acl_id = aws_network_acl.vpc-test.id
  rule_number = 200
  egress = false
  protocol = "tcp"
  rule_action = "allow"
  cidr_block = "10.0.0.0/24"
  from_port = 22
  to_port = 22
}

resource "aws_network_acl_rule" "new-rule" {
  network_acl_id = aws_network_acl.vpc-test.id
  rule_number = 200
  egress = false
  protocol = "tcp"
  rule_action = "allow"
  cidr_block = "10.0.0.0/24"
  from_port = 22
  to_port = 22
}
  • Apply the Terraform configuration.
  • Delete one of the ACL rules.
  • Observe the unexpected removal of the corresponding Network ACL entry from AWS.

The EC2 CreateNetworkAclEntry API succeeds on the second resource Create if all attributes are identical. Prevent this.

Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/vpc Issues and PRs that pertain to the vpc service. label Mar 12, 2024
@ewbankkit ewbankkit added the bug Addresses a defect in current functionality. label Mar 12, 2024
@ewbankkit
Copy link
Contributor Author

ewbankkit commented Mar 12, 2024

Check also aws_route and security group rules.
Routes require the same treatment, security group rules do not: InvalidPermission.Duplicate: the specified rule "peer: 10.0.0.0/8, TCP, from port: 80, to port: 8080, ALLOW" already exists.

@github-actions github-actions bot added this to the v5.41.0 milestone Mar 12, 2024
Copy link

This functionality has been released in v5.41.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!

@jhenry82
Copy link

So I understand the rationale for fixing the issue of creating duplicate resources. It has left us in a bit of a bind, however. We are using an in-house module that inadvertently created some duplicate aws_route resources. Today we upgraded to the latest provider release, and the module began failing on those duplicate routes. I can easily remove one set of routes from the code. But if I do that, Terraform of course wants to delete the route. Then we have to do another plan and apply so it notices the route is gone, and recreates it using the remaining copy of the aws_route resource. Doing this in production will cause an outage. Which I would really like to avoid. Finding a breaking change in a minor version release is also frustrating, even if it is technically correct.

Do you have any suggested workarounds? I tried using various moved{} blocks in the hopes that would prevent Terraform from deleting the route, but it had no effect. The best I can come up with is making sure we do a "terraform state rm" on the affected routes before applying.

@ewbankkit
Copy link
Contributor Author

@jhenry82 You should be able to use a removed block.

Copy link

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 have found a problem that seems similar to this, 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 Apr 21, 2024
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/vpc Issues and PRs that pertain to the vpc service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants