Provides an AWS EBS Volume Attachment as a top level resource, to attach and detach volumes from AWS Instances.
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_instance" "web" {
ami = "ami-21f78e11"
availability_zone = "us-west-2a"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
resource "aws_ebs_volume" "example" {
availability_zone = "us-west-2a"
size = 1
}
This resource supports the following arguments:
device_name
- (Required) The device name to expose to the instance (for
example, /dev/sdh
or xvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information.instance_id
- (Required) ID of the Instance to attach tovolume_id
- (Required) ID of the Volume to be attachedforce_detach
- (Optional, Boolean) Set to true
if you want to force the
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
Detaching an Amazon EBS Volume from an Instance for more information.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
means attached.stop_instance_before_detaching
- (Optional, Boolean) Set this to true to ensure that the target instance is stopped
before trying to detach the volume. Stops the instance, if it is not already stopped.This resource exports the following attributes in addition to the arguments above:
device_name
- The device name exposed to the instanceinstance_id
- ID of the Instancevolume_id
- ID of the VolumeIn Terraform v1.5.0 and later, use an import
block to import EBS Volume Attachments using DEVICE_NAME:VOLUME_ID:INSTANCE_ID
. For example:
import {
to = aws_volume_attachment.example
id = "/dev/sdh:vol-049df61146c4d7901:i-12345678"
}
Using terraform import
, import EBS Volume Attachments using DEVICE_NAME:VOLUME_ID:INSTANCE_ID
. For example:
% terraform import aws_volume_attachment.example /dev/sdh:vol-049df61146c4d7901:i-12345678