2015-05-28 17:33:20 +02:00
---
layout: "aws"
page_title: "AWS: aws_volume_attachment"
sidebar_current: "docs-aws-resource-volume-attachment"
description: |-
Provides an AWS EBS Volume Attachment
---
# aws\_volume\_attachment
Provides an AWS EBS Volume Attachment as a top level resource, to attach and
detach volumes from AWS Instances.
2016-03-25 18:12:01 +01:00
~> **NOTE on EBS block devices:** If you use `ebs_block_device` on an `aws_instance` , Terraform will assume management over the full set of non-root EBS block devices for the instance, and treats additional block devices as drift. For this reason, `ebs_block_device` cannot be mixed with external `aws_ebs_volume` + `aws_ebs_volume_attachment` resources for a given instance.
2015-05-28 17:33:20 +02:00
## Example Usage
```
resource "aws_volume_attachment" "ebs_att" {
device_name = "/dev/sdh"
2017-02-18 23:48:50 +01:00
volume_id = "${aws_ebs_volume.example.id}"
2015-05-28 17:33:20 +02:00
instance_id = "${aws_instance.web.id}"
}
resource "aws_instance" "web" {
2017-02-18 23:48:50 +01:00
ami = "ami-21f78e11"
2015-05-28 17:33:20 +02:00
availability_zone = "us-west-2a"
2017-02-18 23:48:50 +01:00
instance_type = "t1.micro"
2015-05-28 17:33:20 +02:00
tags {
Name = "HelloWorld"
}
}
resource "aws_ebs_volume" "example" {
availability_zone = "us-west-2a"
2017-02-18 23:48:50 +01:00
size = 1
2015-05-28 17:33:20 +02:00
}
```
## Argument Reference
The following arguments are supported:
2017-02-18 23:48:50 +01:00
* `device_name` - (Required) The device name to expose to the instance (for
2015-05-28 17:33:20 +02:00
example, `/dev/sdh` or `xvdh` )
* `instance_id` - (Required) ID of the Instance to attach to
* `volume_id` - (Required) ID of the Volume to be attached
* `force_detach` - (Optional, Boolean) Set to `true` if you want to force the
2017-02-18 23:48:50 +01:00
volume to detach. Useful if previous attempts failed, but use this option only
as a last resort, as this can result in **data loss** . See
2015-05-28 17:33:20 +02:00
[Detaching an Amazon EBS Volume from an Instance][1] for more information.
2017-02-18 23:48:50 +01:00
* `skip_destroy` - (Optional, Boolean) Set this to true if you do not wish
to detach the volume from the instance to which it is attached at destroy
time, and instead just remove the attachment from Terraform state. This is
useful when destroying an instance which has volumes created by some other
2016-11-02 16:29:37 +01:00
means attached.
2015-05-28 17:33:20 +02:00
## Attributes Reference
* `device_name` - The device name exposed to the instance
* `instance_id` - ID of the Instance
2017-02-18 23:48:50 +01:00
* `volume_id` - ID of the Volume
2015-05-28 17:33:20 +02:00
2016-01-14 21:55:39 +01:00
[1]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html