# Detach some ebs volume from EC2 Instance (aws)

**URL:** <https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604>\
**Category:** Terraform\
**Created:** [June 4, 2020, 8:07pm UTC](https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604 "2020-06-04T20:07:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FranciscoJLucca](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/franciscojlucca/32/7620_2.png) [@FranciscoJLucca](https://discuss.hashicorp.com/u/FranciscoJLucca)\
**Post date:** [June 4, 2020, 8:07pm UTC](https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604/1 "2020-06-04T20:07:20Z")

</div>

Hi,  
I need to detach a volume from ec2 instance, in the documentation I only find aws\_volume\_attachment. Does exist something like aws\_volume\_deattachment ?

---

<div class="post-metadata">

**Author:** ![javierruizjimenez](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/javierruizjimenez/32/10134_2.png) [@javierruizjimenez](https://discuss.hashicorp.com/u/javierruizjimenez)\
**Post date:** [June 4, 2020, 8:48pm UTC](https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604/2 "2020-06-04T20:48:35Z")

</div>

Just run the plan without the aws\_volume\_attachment and Terraform will remove the volume.

Terraform makes all the necessary changes to have the same infrastructure in code as in AWS. Anything missing in AWS will be created and any thing missing in code will be removed from AWS.

---

<div class="post-metadata">

**Author:** ![FranciscoJLucca](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/franciscojlucca/32/7620_2.png) [@FranciscoJLucca](https://discuss.hashicorp.com/u/FranciscoJLucca)\
**Post date:** [June 12, 2020, 12:28pm UTC](https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604/3 "2020-06-12T12:28:23Z")

</div>

Hi,  
I tried and it doesn’t work, when I run the plan I get as output: “Plan: 1 to add, 0 to change, 0 to destroy.”

---

<div class="post-metadata">

**Author:** ![javierruizjimenez](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/javierruizjimenez/32/10134_2.png) [@javierruizjimenez](https://discuss.hashicorp.com/u/javierruizjimenez)\
**Post date:** [June 12, 2020, 1:33pm UTC](https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604/4 "2020-06-12T13:33:46Z")

</div>

You can only delete resources that were created with Terraform or that have been imported from the IaaS into the Terraform state file.

Did you attached the volume using Terraform? Is the volume still attached? Did you create the EC2 instance using Terraform?

Maybe you can share the code and the execution result.

---

<div class="post-metadata">

**Author:** ![FranciscoJLucca](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/franciscojlucca/32/7620_2.png) [@FranciscoJLucca](https://discuss.hashicorp.com/u/FranciscoJLucca)\
**Post date:** [June 13, 2020, 7:11pm UTC](https://discuss.hashicorp.com/t/detach-some-ebs-volume-from-ec2-instance-aws/9604/5 "2020-06-13T19:11:50Z")

</div>

I have two files, my main where I use to create my instance and have other file I specify my Ec2 resources. I will let the code below.

resource “aws\_instance” “web” {  
ami = “{var.ami\_id}" instance\_type = "{var.instance\_type}”  
availability\_zone = “{var.availability\_zoneEc2}" subnet\_id = "{var.subnet\_id}”  
security\_groups = ["${aws\_security\_group.allow\_ssh.name}"]

tags = {  
Name = “terraformEc2”  
}  
}

resource “aws\_ebs\_volume” “example” {  
availability\_zone = “{var.availability\_zoneEbs}" size = "{var.size}”  
tags = {  
Name = “terraformEBS”  
}  
}

resource “aws\_volume\_attachment” “ebs\_att” {  
device\_name = “/dev/sdh”  
volume\_id = “{aws\_ebs\_volume.example.id}" instance\_id = "{aws\_instance.web.id}”  
}

resource “aws\_security\_group” “allow\_ssh” {  
name = “allow\_ssh”  
ingress {  
from\_port = 22  
to\_port = 22  
protocol = “tcp”  
cidr\_blocks = [“0.0.0.0/0”]  
}  
egress {  
from\_port = 0  
to\_port = 0  
protocol = -1  
cidr\_blocks = [“0.0.0.0/0”]  
}  
}
