hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.17k forks source link

[Bug]: aws_security_group destruction stucks on HTTP 400 response, masking issues with an incorrect plan #29009

Open ei-grad opened 1 year ago

ei-grad commented 1 year ago

Terraform Core Version

1.3.7

AWS Provider Version

4.51.0

Affected Resource(s)

aws_security_group

Expected Behavior

  1. When removing the security group along the rules referencing it, at first the rules should be deleted, then the group. Dependent resource must be updated to be independent from dependency before its dependency could be destroyed.
  2. During this operation, if terraform triggers a request which results in an HTTP 400 response from AWS API - the operation should be cancelled and considered failed.

Actual Behavior

Terraform tries to destroy the security group before removing the rules referencing it, and stucks in a loop receiving HTTP 400 from AWS for continuously retrying incorrect requests.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

Initial state:

resource "aws_security_group" "test1" {
  name = "test1"
  ingress {
    protocol  = "-1"
    from_port = 0
    to_port   = 0
    security_groups = [
      aws_security_group.test2.id,
    ]
  }
}

resource "aws_security_group" "test2" {
  name = "test2"
}

Target state:

resource "aws_security_group" "test1" {
  name = "test1"
  ingress {
    protocol  = "-1"
    from_port = 0
    to_port   = 0
    cidr_blocks = ["0.0.0.0/0"]
  }
}

# aws_security_group.test2 removed

Steps to Reproduce

  1. Create test1 and test2 security rules, where test1 group has the rule referencing test2
  2. Try to remove test2 along with the rule referencing it in a single terraform apply.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

Similar issue - #265, it points on a wrong (IMO) facts, and contains a long discussion with some unrelated things, so I decided to start a new one.

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 1 year ago

Similar to #27476