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

Security Group tries to be destroyed before detaching from RDS Cluster #9692

Open
lfventura opened this issue Aug 9, 2019 · 10 comments
Open
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service.

Comments

@lfventura
Copy link

lfventura commented Aug 9, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.6

  • provider.aws v2.23.0
  • provider.random v2.2.0

Affected Resource(s)

  • aws_security_group
  • aws_rds_cluster

Terraform Configuration Files

Debug Output

Panic Output

No Panic Output, just keeps trying to delete the SG indefinetely

Expected Behavior

The SG should be deleted after updating the RDS Cluster SGs

Actual Behavior

It tries to delete the SG before removing the SG from RDS Cluster

Steps to Reproduce

  1. First run a code that will create the SG and add it to the RDS Cluster
resource "aws_rds_cluster" "this" {
... 
  vpc_security_group_ids              = var.allowed_security_groups_count > 0 ? concat([aws_security_group.this[0].id], var.vpc_security_group_ids) : var.vpc_security_group_ids
...
}

resource "aws_security_group" "this" {
  count = var.allowed_security_groups_count > 0 ? 1 : 0
  name_prefix = "${var.name}-"
  vpc_id      = var.vpc_id
  tags = var.tags
}

variable "allowed_security_groups_count" {
  default = 1
}

variable "vpc_security_group_ids" {
  default = ["sg-aaaaaaaa"]
}
  1. Then update the code for something that will destroy the SG, Example:
resource "aws_rds_cluster" "this" {
... 
  vpc_security_group_ids              = var.allowed_security_groups_count > 0 ? concat([aws_security_group.this[0].id], var.vpc_security_group_ids) : var.vpc_security_group_ids
...
}

resource "aws_security_group" "this" {
  count = var.allowed_security_groups_count > 0 ? 1 : 0
  name_prefix = "${var.name}-"
  vpc_id      = var.vpc_id
  tags = var.tags
}

variable "allowed_security_groups_count" {
  default = 0
}

variable "vpc_security_group_ids" {
  default = ["sg-aaaaaaaa"]
}

Terraform will recognize that the SG needs to be destroyed and removed from RDS Cluster, but it keeps trying to remove the SG before detaching it from the RDS Cluster.

Important Factoids

Nothing

References

@ghost ghost added service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. labels Aug 9, 2019
@bflad bflad added the needs-triage Waiting for first response or review from a maintainer. label Aug 12, 2019
@brucedvgw
Copy link

Just encountered this issue in v0.12.17.

I had to manually remove the security group from the RDS instances and then run the terraform apply again for it to destroy/replace them. However it didn't re-attach them to the RDS instances. I had to run it again for it t pick up that this also needed updating.

@rehevkor5
Copy link
Contributor

This occurs with security groups attached to aws_vpc_endpoint resources, too.

@janosmiko
Copy link

This issue still exist with:

  • Terraform v0.12.24

  • provider.aws v2.53.0

@emmm-dee
Copy link

emmm-dee commented Oct 8, 2020

Confirming this is still a problem in versions. In my case I have EC2 instances attached to the SG and it does not try to detach before destroying the SG.

Terraform v0.12.29
+ provider.aws v3.9.0

@klolik
Copy link

klolik commented Aug 6, 2021

Same for load balancer attached security groups.

Renaming TF resource resource "aws_security_group" "this" to resource "aws_security_group" "that" makes TF stuck trying to destroy this security group when it still is applied to application load balancer.

  • Terraform v0.12.31
  • provider.aws 3.26.0

@c4milo
Copy link
Contributor

c4milo commented Nov 18, 2021

It happens as well to SGs attached through ASGs.

@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 9, 2021
@pspot2
Copy link

pspot2 commented Dec 23, 2021

Also applies to VPC endpoint implicitly created by aws_transfer_server resource.

@cfernhout
Copy link

I have the same issue with RDS and VPC SG. Running TF v1.1.9 & AWS v4.8.0

@demisx
Copy link

demisx commented Sep 23, 2023

Similar issue with EC2 instance hashicorp/terraform#8617. Does anyone have any workaround for disassociating security group first?

@emmaLP
Copy link

emmaLP commented Jul 3, 2024

Getting this issue when leveraged the AWS provider RDS tf module.

I've tried the create_before_destroy option on the security group, you can see the RDS security_group_rule get updated but this doesn't not get applied to the rds cluster.

I am having to manually updated the attached security groups to a RDS instance for the new security group to be added

Please can we get an update on this please or has anyone found a non manual workaround for this please

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/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service.
Projects
None yet
Development

No branches or pull requests