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

aws_volume_attachment Error waiting for Volume #4770

Closed
jrobison-sb opened this issue Jun 6, 2018 · 33 comments · Fixed by #21144
Closed

aws_volume_attachment Error waiting for Volume #4770

jrobison-sb opened this issue Jun 6, 2018 · 33 comments · Fixed by #21144
Assignees
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@jrobison-sb
Copy link
Contributor

Terraform Version

Terraform v0.11.7

  • provider.aws v1.20.0

Affected Resource(s)

aws_volume_attachment

Actual Behavior

When running a terraform destroy, in which you want to destroy an aws_instance and it's aws_volume_attachment, terraform (or the AWS API) will attempt to destroy the volume attachment first, then then instance second. This often fails because Error waiting for Volume (vol-010b3d979b1027867) to detach from Instance.

Expected Behavior

If an aws_volume_attachment was going to be destroyed, and the associated aws_instance was also going to be destroyed, it would make sense to destroy the instance first and then the aws_volume_attachment second, which would never run any risk of timing out.

Steps to Reproduce

  1. Create an aws_ebs_volume, an aws_instance, and a aws_volume_attachment.
  2. terraform destroy
@YektaLeblebici
Copy link

I can confirm this for our infra too. On latest Terraform, destroying aws_volume_attachment and aws_instance together fails with this timeout error.

@radeksimko radeksimko added bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels Jun 13, 2018
@alexaandru
Copy link

Running into this as well.

@Hashfyre
Copy link

➜ tfa
data.aws_availability_zones.az: Refreshing state...
data.aws_route53_zone.int-orgaws: Refreshing state...
data.aws_route53_zone.orgaws: Refreshing state...
data.aws_vpc.stage-org: Refreshing state...
data.aws_ami.stage-mongodb: Refreshing state...
data.aws_subnet.stage-mongodb: Refreshing state...
data.aws_security_group.stage-mongodb: Refreshing state...
aws_instance.stage-mongodb: Refreshing state... (ID: i-xxxxxxxxxxxxxxxxxxx)
aws_route53_record.stage-mongodb-int: Refreshing state... (ID: ACCID-stage-mongodb-int_A)
aws_ebs_volume.stage-mongodb-volume-a: Refreshing state... (ID: vol-xxxxxxxxxxx)
aws_volume_attachment.stage-mongodb-volume-attachment-a: Refreshing state... (ID: vai-xxxxxxxxx)

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  - aws_ebs_volume.stage-mongodb-volume-a

  - aws_instance.stage-mongodb

  - aws_route53_record.stage-mongodb-int

  - aws_volume_attachment.stage-mongodb-volume-attachment-a


Plan: 0 to add, 0 to change, 4 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_volume_attachment.stage-mongodb-volume-attachment-a: Destroying... (ID: vai-xxxxxxxxxxx)
aws_route53_record.stage-mongodb-int: Destroying... (ID: ACCID-stage-mongodb-int_A)
aws_volume_attachment.stage-mongodb-volume-attachment-a: Still destroying... (ID: vai-385500658, 10s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 10s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 20s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 30s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 40s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 50s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 1m0s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 1m10s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 1m20s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 1m30s elapsed)
aws_route53_record.stage-mongodb-int: Still destroying... (ID: ACCID-stage-mongodb-int_A, 1m40s elapsed)
aws_route53_record.stage-mongodb-int: Destruction complete after 1m40s

Error: Error applying plan:

1 error(s) occurred:

* aws_volume_attachment.stage-mongodb-volume-attachment-a (destroy): 1 error(s) occurred:

* aws_volume_attachment.stage-mongodb-volume-attachment-a: Error waiting for Volume (vol-xxxxxxxxxxxxx) to detach from Instance: i-xxxxxxxxxxxxx

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

@queglay
Copy link

queglay commented Feb 4, 2019

this is also a problem if ebs volume ids are replaced in the template, you'll get a similar error. if a volume can't be detached, it would be good to have a variable that did both these things-
shutdown instances if volumes can't be detached
startup instances after volume detachments and attachments are complete.

this would also help when doing terraform destroy.

I've attached an example below from changing the aws_volume_attachement name that causes the same problem.

Error: Error applying plan:

5 error(s) occurred:

  • module.softnas.aws_volume_attachment.ebs_att[0] (destroy): 1 error(s) occurred:

  • aws_volume_attachment.ebs_att.0: Error waiting for Volume (vol-0dfdb289f3a00f63c) to detach from Instance: i-055c1f1bd7d1b417c

  • module.softnas.aws_cloudformation_stack.SoftNAS1Stack: 1 error(s) occurred:

  • aws_cloudformation_stack.SoftNAS1Stack: Creating CloudFormation stack failed: AlreadyExistsException: Stack [FCB-SoftNAS1Stack] already exists
    status code: 400, request id: 303555c9-287f-11e9-b20c-4d54279ee980

  • module.softnas.aws_volume_attachment.ebs_att[1] (destroy): 1 error(s) occurred:

  • aws_volume_attachment.ebs_att.1: Error waiting for Volume (vol-071219d59b8153d6a) to detach from Instance: i-055c1f1bd7d1b417c

  • module.softnas.aws_volume_attachment.ebs_att[3] (destroy): 1 error(s) occurred:

  • aws_volume_attachment.ebs_att.3: Error waiting for Volume (vol-0c0703a9c333cef86) to detach from Instance: i-055c1f1bd7d1b417c

  • module.softnas.aws_volume_attachment.ebs_att[2] (destroy): 1 error(s) occurred:

  • aws_volume_attachment.ebs_att.2: Error waiting for Volume (vol-0a21cf466c807a753) to detach from Instance: i-055c1f1bd7d1b417c

@mikaelforeseeti
Copy link

I ran into this today, is there a workaround? I tried running terraform destroy --target=module.machines.ep_instance but it still tries to destroy the volume_attachment object first.

@paulrowlands
Copy link

FYI, I ran into this when implementing Windows servers with MSSQL.

I found that adding a null_resource which has a depends_on for the instance and a remote-exec provisioner which includes a 'when = "destroy"' option and executes a Powershell command stop the MSSQLSERVER service on the host.

After this, terraform destroy will destroy the attachment.

You could replace the MSSQL service with relevant shell commands to stop services, unmount disks, etc.

@yum-dev
Copy link

yum-dev commented Jun 12, 2019

Even I'm facing this issue.

Terraform v0.12.1

  • provider.aws v2.14.0

@DrHashi
Copy link

DrHashi commented Jul 11, 2019

Terraform v0.12.3

  • provider.aws v2.18.0

Still failing...

@kingindanord
Copy link

I have the same issue

Terraform v0.12.5

  • provider.aws v2.20.0

@twarnock
Copy link

twarnock commented Aug 7, 2019

We are facing this issue as well.

Terraform v0.12.5
provider.aws v2.22

@AndreiF8
Copy link

Facing same issue

Terraform v0.11.14

  • provider.aws v2.25.0

@pitthecat
Copy link

We have the same problem

Terraform 0.12.7 and provider AWS 2.25.0

@RiceAndMeet
Copy link

Facing the same issue here, we worked around it by including skip_destroy = true in resource aws_volume_attachment.

According to the documentation, setting skip_destroy = true will remove resource aws_volume_attachment from the state file, and this will unblock terraform destroy operation.

@kreempuff
Copy link

kreempuff commented Dec 25, 2019

Hey all, Happy Holidays.
What fixed it for me was the first line here:

You can detach an Amazon EBS volume from an instance explicitly or by terminating the instance. However, if the instance is running, you must first unmount the volume from the instance.

If the volume is still mounted on the instance, it will never detach (it even shows gray in the AWS console, so terraform may be able to help us here). Debugging terraform with export TF_LOG=TRACE showed that the api returned a 200 OK for the DetachVolume api call, but subsequent calls to DescribeVolume showed the volume as busy.

After I unmounted the volume, terraform destroyed the volume attachment successfully.

@twarnock
Copy link

twarnock commented Jan 10, 2020

If we're listing workarounds, shutting down the instance before the destroy will work as well. The detach will work since the volume would not be "busy" at that point.

@edsale
Copy link

edsale commented Jan 28, 2020

Same problem here. Only been a bug 19 months. Could we get Terraform to STOP instances with attached storage, DETACH/DELETE all volumes and then TERMINATE the instance? Seems like a fundamental function fails often in this circumstance.

@yogeshsajanikar
Copy link

Probably there should be a provision to run a script just before volume is detached.

@janosmiko
Copy link

+1 here
Terraform version: 0.12.25
AWS Provider version: 2.65.0

@ghost
Copy link

ghost commented Jul 4, 2020

another day, another issue with super basic stuff expected from TF. No response from TF also.

For the record:

  • Terraform v0.12.26

Issue persists.

@onezeroecho
Copy link

Got this issue too.

Terraform v0.12.28
+ provider.aws v2.63.0

@shrilesh1986
Copy link

Encountered Same issue, have to manually unmount to volume and then proceed with terraform destroy.

@stijnopheide
Copy link

stijnopheide commented Aug 26, 2020

persists in

terraform v0.13.0
provider.aws v2.77.0

@Jouo
Copy link

Jouo commented Oct 13, 2020

Problem still here
Terraform v0.13.4
AWS v3.10.0

@juloi
Copy link

juloi commented Nov 24, 2020

Same problem!!!

terraform v0.13.2
provider.aws  ~> 3.0

@dogewithit
Copy link

Same issue for me

image

@maciejjakub
Copy link

Same issue. We're using Terraform v0.13.4.

@dstamen
Copy link

dstamen commented Jul 20, 2021

still hitting this with terraform 1.0.2 and AWS provider 3.5. stopping the instance first allowed me to destroy.

Terraform v1.0.2
on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v3.50.0

@Illutax
Copy link

Illutax commented Aug 18, 2021

Couldn't detatch volume, not even with EC2 Management Console. The volume attachment was in state detaching. I manually stopped the instance, then the attachment was successfully detached by itself.
After that i started the instance again and the terraform apply ran successfully.

Was using Terraform v0.12.31
aws-cli v2.2.18

@RawthiL
Copy link

RawthiL commented Sep 6, 2021

Same here, using:

  • Terraform v1.0.5
  • hashicorp/aws 3.24.1
  • aws-cli/2.2.16 Python/3.8.8 Linux/5.11.0-27-generic exe/x86_64.ubuntu.20 prompt/off (I'm not sure if this is relevant)

If the volume is mounted the destruction fails, however if I unmount the volume then the attachment destruction, and later the instance destruction, both succeed. While this is logical, I would expect terraform to first destroy the instance (unmounting the volume in the process) and then destroy the volume attachment.

mcdonnnj added a commit to cisagov/cyhy_amis that referenced this issue Sep 8, 2021
This logic was used to ensure that the EC2 instance for an AWS EBS volume
attachment was in a terminated state so that the volume attachment could be
destroyed successfully. This has not been an issue in more recent COOL
configurations so we are removing it here. In the event that this is still an
problem a relevant issue can be found at:
hashicorp/terraform-provider-aws#4770
@ughstudios
Copy link

I'm also having this issue in terraform 1.0.7

@YakDriver YakDriver self-assigned this Oct 4, 2021
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
@YakDriver
Copy link
Member

Thank you for reporting this and your continued interest. This issue should be resolved with the feature added in #21144. If that does not resolve the issue, please open a new issue and reference this one.

@github-actions
Copy link

github-actions bot commented Oct 8, 2021

This functionality has been released in v3.62.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 Jun 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 Jun 3, 2022
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.
Projects
None yet