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

[Bug]: DependencyViolation with ENIs associated with security group of lambda #37046

Closed
vamshidhar-rapolu opened this issue Apr 22, 2024 · 6 comments
Labels
bug Addresses a defect in current functionality. service/lambda Issues and PRs that pertain to the lambda service. service/vpc Issues and PRs that pertain to the vpc service.
Milestone

Comments

@vamshidhar-rapolu
Copy link

vamshidhar-rapolu commented Apr 22, 2024

Terraform Core Version

1.8.1

AWS Provider Version

5.46.0

Affected Resource(s)

aws_security_group

Expected Behavior

Terraform destroy of the lambda is expected to be successful with the aws_security_group being destroyed successfully. This works using the aws provider version 5.45.0

Actual Behavior

Terraform destroy fails to delete the security group of the lambda due to dependency on the network interface eni.
╷ │ Error: deleting Security Group (sg-xxxxxxxxxxxxxxxxx): DependencyViolation: resource sg-xxxxxxxxxxxxxxxxx has a dependent object │ status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │ │ ╵

Deleting the network interface(s) associated with the security group manually and retrying the terraform destroy works as expected.

Relevant Error/Panic Output Snippet

╷
│ Error: deleting Security Group (sg-xxxxxxxxxxxxxxxxx): DependencyViolation: resource sg-xxxxxxxxxxxxxxxxx has a dependent object
│ 	status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
│ 
│ 
╵

Terraform Configuration Files

resource "aws_security_group" "this" {
  name   = "Redacted"
  vpc_id = "Redacted"

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["Redacted"]
  }
}

resource "aws_lambda_function" "lambda1" {
  description      = "Redacted"
  filename         = data.archive_file.Redacted.output_path
  function_name    = "Redacted"
  handler          = "Redacted.lambda_handler"
  role             = aws_iam_role.Redacted.arn
  runtime          = "python3.9"
  source_code_hash = data.archive_file.Redacted.output_base64sha256
  timeout          = 30

  vpc_config {
    subnet_ids         = var.subnet_ids
    security_group_ids = [aws_security_group.this.id]
  }
}

resource "aws_lambda_function" "lambda2" {
  description      = "Redacted"
  filename         = data.archive_file.Redacted.output_path
  function_name    = "Redacted"
  handler          = "Redacted.lambda_handler"
  role             = aws_iam_role.Redacted.arn
  runtime          = "python3.9"
  source_code_hash = data.archive_file.Redacted.output_base64sha256
  timeout          = 30

  vpc_config {
    subnet_ids         = var.subnet_ids
    security_group_ids = [aws_security_group.this.id]
  }
}

Steps to Reproduce

Running terraform destroy isn't successful with aws provider 5.46.0 due to the DependencyViolation error stated above.

Debug Output

No response

Panic Output

No response

Important Factoids

There is no issue with the destroy run using the aws provider version 5.45.0

References

Relates #32756.

Would you like to implement a fix?

None

@vamshidhar-rapolu vamshidhar-rapolu added the bug Addresses a defect in current functionality. label Apr 22, 2024
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 service/lambda Issues and PRs that pertain to the lambda service. service/vpc Issues and PRs that pertain to the vpc service. labels Apr 22, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 22, 2024
@aniketcds
Copy link

i am also facing the same issue, security group stucks in still destroying...

@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Apr 23, 2024
@ewbankkit
Copy link
Contributor

ewbankkit commented Apr 24, 2024

My guess is that it's this change in internal/service/ec2/vpc_network_interface.go, deleteLingeringENIs:

	for _, eni := range enis {
		- eni := eni
		+ eni := &eni

This should be fixed by this week's upgrade to Go 1.22 (language change to "for" loop variables): #36996.

@vamshidhar-rapolu After tomorrow's Terraform AWS Provider v5.47.0 release could you please download the new version and retry? Thanks.

@vamshidhar-rapolu
Copy link
Author

vamshidhar-rapolu commented Apr 26, 2024

@ewbankkit The issue seems to be resolved with 5.47.0. I don't see any errors with the deletion of security group.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@ewbankkit ewbankkit added this to the v5.47.0 milestone Apr 26, 2024
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/lambda Issues and PRs that pertain to the lambda service. service/vpc Issues and PRs that pertain to the vpc service.
Projects
None yet
Development

No branches or pull requests

3 participants