Resource: aws_volume_attachment

Provides an AWS EBS Volume Attachment as a top level resource, to attach and detach volumes from AWS Instances.

Example Usage

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
}

Argument Reference

This resource supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In 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