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

Terraform is not removing tainted aws_resource and it's failing to remove aws_volume_attachment #288

Closed
hashibot opened this issue Jun 13, 2017 · 2 comments · Fixed by #21144
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Milestone

Comments

@hashibot
Copy link

This issue was originally opened by @hgontijo as hashicorp/terraform#9065. It was migrated here as part of the provider split. The original body of the issue is below.


Terraform Version

0.7.4

Affected Resource(s)

  • aws_volume_attachment
  • aws_instance

Terraform Configuration Files

resource "aws_instance" "teamcity_server" {
  ami = "${var.server_ami}"
  availability_zone = "${var.server_az}"
  instance_type = "${var.server_instance_type}"
  vpc_security_group_ids = [ "${split(",", var.security_groups)}" ]
  subnet_id = "${var.subnet_id}"

  key_name = "${var.key_name}"
  iam_instance_profile = "tc-server"

  root_block_device {
    volume_type = "gp2"
  }
}

resource "aws_ebs_volume" "data_volume" {
  availability_zone = "${var.server_az}"
  snapshot_id = "${var.data_volume_snapshot}"
  size = "${var.data_volume_size}"
  type = "gp2"
}

resource "aws_volume_attachment" "data_volume_attachment" {
  device_name = "/dev/sdf"
  instance_id = "${aws_instance.teamcity_server.id}"
  volume_id = "${aws_ebs_volume.data_volume.id}"
}

I ommited non-relevant parts.

Expected Behavior

Since the aws_instance has an aws_volume_attachment, we used to taint aws_instance before running terraform destroy to ensure the instance is marked for deletion so that aws_instance, aws_volume_attachment, aws_ebs_volume are properly destroyed regardless of the volume attachment dependency. This was working fine until v0.6.16.

Actual Behavior

$ terraform taint -no-color -allow-missing -module=teamcity aws_instance.teamcity_server
The resource aws_instance.teamcity_server in the module root.teamcity has been marked as tainted!
$ terraform destroy
...
Error applying plan:

1 error(s) occurred:

* aws_volume_attachment.data_volume_attachment: Error waiting for Volume (vol-af94311b) to detach from Instance: i-a6182dbe

Full logs

Based on the logs, aws_instance is not being removed as expected by running taint before destroy.

Steps to Reproduce

  1. terraform apply
  2. `terraform taint -no-color -allow-missing -module=teamcity aws_instance.teamcity_server``
  3. terraform destroy

References

That maybe related to:

@github-actions
Copy link

github-actions bot commented Apr 4, 2020

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Apr 4, 2020
@github-actions github-actions bot closed this as completed May 4, 2020
@ghost
Copy link

ghost commented Jun 4, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 4, 2020
YakDriver pushed a commit that referenced this issue Oct 4, 2021
…lume

By stopping the instance, the volume is unmounted in the instance
and the detaching of the volume doesn't run into a timeout

fixes #6673
fixes #2084
fixes #2957
fixes #4770
fixes #288
fixes #1017
@github-actions github-actions bot added this to the v3.62.0 milestone Oct 5, 2021
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/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
2 participants