-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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 workflow with skip_destroy #1017
Comments
I can't confirm this behaviour with terraform 0.10.8 and terraform-aws 1.1.0. Example code: https://gist.github.com/njam/cf572606f23625b941aa7ab61e2569b3 |
I'm currently trying to figure out how to deal with this, I think the problem with your plan, and the problem that OP missed in his workflow, is the timeout commonly occurs when you try to destroy an attachment while it is still mounted. If you unmount the volume first, then run I just started with Terraform and I "solved" the problem like so:
The problem I'm having however, is I think I'm running into hashicorp/terraform#16237, where the destroy provisioner causes a cycle. I can solve the cycle by either 1. hard coding the instance's IP or 2. Adding in a I thought there might be prior work on this, but it seems everyone is using |
Also running into this issue. In our case, we're trying to use the remote provisioner to stop services and unmount an EBS volume "cleanly", this failed due to running into cycle issues exactly as @nemosupremo stated. Our workaround is to do a dirty detachment using |
I'm using:
I believe that the problem is that AWS can't/won't detach the volume from the running FreeBSD instance. If I power down the instance first via the UI or I see a PR (#8602) that adds a If I modify the configuration, setting I don't see any mention of this issue in the docs, The particular error that I'm seeing when destroying is:
For completeness' sake, here's a test case (you'll need to subscribe to the CentOS ami; adjust the security group as necessary):
|
I overcame the issue here and the issues identified in #13549 and #16237 by working with a provisioner attached to a Collect all of the dependent attributes into a # Use your imagination for the missing code
resource "aws_instance" "my_server" {}
resource "aws_volume_attachment" "my_ebs_volume" {}
resource "null_resource" "ebs_volume_cleanup" {
triggers = {
private_ip = aws_instance.my_server.private_ip
instance_id = aws_instance.my_server.id # Trigger on this in addition to the private_ip in case you use a static IP
data_volume_attachment = aws_volume_attachment.my_ebs_volume.volume_id
}
provisioner "remote-exec" {
when = "destroy"
inline = [
"sudo service my-service stop",
"sudo sync",
"if mount | grep '/path/to/volume'; then sudo umount /path/to/volume; fi",
]
connection {
user = "ubuntu"
host = self.triggers.private_ip
private_key = "${file("/path/to/local/keyfile")}"
}
}
} Passing the This gives you a workflow that can cleanly execute like this to replace a server without destroying/recreating the EBS volume: terraform taint aws_instance.my_server
terraform apply -auto-approve |
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! |
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. |
Terraform 0.9.8
Firstly, I feel that aws_volume_attachment should always have skip_destroy=true as default. aws_volume_attachments are notoriously tricky in terraform, because they often prevent destruction of resources.
For example, terraform up an aws_instance, an aws_ebs_volume, and an aws_volume_attachment that connects them (without skip_destroy), and then try and plan -destroy all 3 (and apply)
Terraform will simply do this:
Worse still, the skip_destroy flag must be successfully APPLIED to the resource IN THE STATEFILE, before you have any hope of terraform destroying it. If the skip_destroy="true" flag is merely on the aws_volume_attachment resource .tf file, and you try and destroy the resource, you still get the above timeout error. - this means the docs are technically wrong.
Sometimes, you destroy resources simply by deleting the
resource
declarations in the terraform code and plan/applying - as this does not work for the same reasons (skip_destroy has not been applied in the statefile), it just means that you then have an impossible situation and have to revert the codebase back, in order to add the flag and then terraform apply before terraform destroying.One of three things should happen (in my view):
Unfortunately there is no lifecycle event to swap the order of destruction of dependencies for (3).
Any comments appreciated - its a bit of a thorny workflow at the moment.
The text was updated successfully, but these errors were encountered: