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 name change forces the replacement but it fails if there are linked interfaces #20743

Closed
speller opened this issue Sep 1, 2021 · 4 comments · Fixed by #26553
Closed
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@speller
Copy link
Contributor

speller commented Sep 1, 2021

Piece of my configuration:

resource "aws_instance" "control" {
  ami = data.aws_ami.control.id
  instance_type = "t2.nano"
  subnet_id = module.vpc.public1_subnet_id
  associate_public_ip_address = true
  vpc_security_group_ids = [
    aws_security_group.control.id
  ]
}

resource "aws_security_group" "control" {
  name = "${local.infra_name_hyphen}-bastion-proxy"
  vpc_id = module.vpc.vpc_id
}

When I change the security group name, it is going to be replaced:

Terraform will perform the following actions:
  # aws_instance.control will be updated in-place
  ~ resource "aws_instance" "control" {
        id                                   = "id"
      ~ vpc_security_group_ids               = [
          - "sg-0b3b4f192869b74db",
        ] -> (known after apply)
        # (27 unchanged attributes hidden)
        # (5 unchanged blocks hidden)
    }
  # aws_security_group.control must be replaced
-/+ resource "aws_security_group" "control" {
      ~ arn                    = "arn:aws:ec2:" -> (known after apply)
      ~ id                     = "sg-0b3b4f192869b74db" -> (known after apply)
      ~ name                   = "review-dev-control-proxy" -> "review-dev-bastion-proxy" # forces replacement
      + name_prefix            = (known after apply)
        # (3 unchanged attributes hidden)
    }

...

aws_security_group.control: Still destroying... [id=sg-0b3b4f192869b74db, 11m50s elapsed]
aws_security_group.control: Still destroying... [id=sg-0b3b4f192869b74db, 12m0s elapsed]
aws_security_group.control: Still destroying... [id=sg-0b3b4f192869b74db, 12m10s elapsed]
aws_security_group.control: Still destroying... [id=sg-0b3b4f192869b74db, 12m20s elapsed]
Error: Error deleting security group: DependencyViolation: resource sg-0b3b4f192869b74db has a dependent object
	status code: 400, request id: 0fb51d70-0632-44f1-ba62-dafd14459175

But changes are failing because the EC2 instance's network interface is linked to the security group.

Such situations should be handled properly.

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/ec2 Issues and PRs that pertain to the ec2 service. labels Sep 1, 2021
@ewbankkit
Copy link
Contributor

@speller Thanks for raising this issue.
The create_before_destroy lifecycle meta-argument added to your aws_security_group resource should help here.

@ewbankkit ewbankkit added question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 1, 2021
@speller
Copy link
Contributor Author

speller commented Sep 2, 2021

Yes, it helps.
I think it would be nice to add some info regarding this to the error output or to the docuemtnation.

@github-actions
Copy link

github-actions bot commented Sep 2, 2022

This functionality has been released in v4.29.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

github-actions bot commented Oct 3, 2022

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 Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants