VolumeAttachment

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

NOTE on EBS block devices: If you use ebs_block_device on an aws.ec2.Instance, this provider 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.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var web = new Aws.Ec2.Instance("web", new Aws.Ec2.InstanceArgs
        {
            Ami = "ami-21f78e11",
            AvailabilityZone = "us-west-2a",
            InstanceType = "t2.micro",
            Tags = 
            {
                { "Name", "HelloWorld" },
            },
        });
        var example = new Aws.Ebs.Volume("example", new Aws.Ebs.VolumeArgs
        {
            AvailabilityZone = "us-west-2a",
            Size = 1,
        });
        var ebsAtt = new Aws.Ec2.VolumeAttachment("ebsAtt", new Aws.Ec2.VolumeAttachmentArgs
        {
            DeviceName = "/dev/sdh",
            VolumeId = example.Id,
            InstanceId = web.Id,
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ebs"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		web, err := ec2.NewInstance(ctx, "web", &ec2.InstanceArgs{
			Ami:              pulumi.String("ami-21f78e11"),
			AvailabilityZone: pulumi.String("us-west-2a"),
			InstanceType:     pulumi.String("t2.micro"),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("HelloWorld"),
			},
		})
		if err != nil {
			return err
		}
		example, err := ebs.NewVolume(ctx, "example", &ebs.VolumeArgs{
			AvailabilityZone: pulumi.String("us-west-2a"),
			Size:             pulumi.Int(1),
		})
		if err != nil {
			return err
		}
		_, err = ec2.NewVolumeAttachment(ctx, "ebsAtt", &ec2.VolumeAttachmentArgs{
			DeviceName: pulumi.String("/dev/sdh"),
			VolumeId:   example.ID(),
			InstanceId: web.ID(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

web = aws.ec2.Instance("web",
    ami="ami-21f78e11",
    availability_zone="us-west-2a",
    instance_type="t2.micro",
    tags={
        "Name": "HelloWorld",
    })
example = aws.ebs.Volume("example",
    availability_zone="us-west-2a",
    size=1)
ebs_att = aws.ec2.VolumeAttachment("ebsAtt",
    device_name="/dev/sdh",
    volume_id=example.id,
    instance_id=web.id)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const web = new aws.ec2.Instance("web", {
    ami: "ami-21f78e11",
    availabilityZone: "us-west-2a",
    instanceType: "t2.micro",
    tags: {
        Name: "HelloWorld",
    },
});
const example = new aws.ebs.Volume("example", {
    availabilityZone: "us-west-2a",
    size: 1,
});
const ebsAtt = new aws.ec2.VolumeAttachment("ebsAtt", {
    deviceName: "/dev/sdh",
    volumeId: example.id,
    instanceId: web.id,
});

Create a VolumeAttachment Resource

new VolumeAttachment(name: string, args: VolumeAttachmentArgs, opts?: CustomResourceOptions);
@overload
def VolumeAttachment(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     device_name: Optional[str] = None,
                     force_detach: Optional[bool] = None,
                     instance_id: Optional[str] = None,
                     skip_destroy: Optional[bool] = None,
                     volume_id: Optional[str] = None)
@overload
def VolumeAttachment(resource_name: str,
                     args: VolumeAttachmentArgs,
                     opts: Optional[ResourceOptions] = None)
func NewVolumeAttachment(ctx *Context, name string, args VolumeAttachmentArgs, opts ...ResourceOption) (*VolumeAttachment, error)
public VolumeAttachment(string name, VolumeAttachmentArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args VolumeAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args VolumeAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args VolumeAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args VolumeAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

VolumeAttachment Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The VolumeAttachment resource accepts the following input properties:

DeviceName string
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.
InstanceId string
ID of the Instance to attach to
VolumeId string
ID of the Volume to be attached
ForceDetach bool
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.
SkipDestroy bool
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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
DeviceName string
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.
InstanceId string
ID of the Instance to attach to
VolumeId string
ID of the Volume to be attached
ForceDetach bool
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.
SkipDestroy bool
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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
deviceName string
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.
instanceId string
ID of the Instance to attach to
volumeId string
ID of the Volume to be attached
forceDetach 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.
skipDestroy 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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
device_name str
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 str
ID of the Instance to attach to
volume_id str
ID of the Volume to be attached
force_detach bool
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 bool
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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.

Outputs

All input properties are implicitly available as output properties. Additionally, the VolumeAttachment resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing VolumeAttachment Resource

Get an existing VolumeAttachment resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: VolumeAttachmentState, opts?: CustomResourceOptions): VolumeAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        device_name: Optional[str] = None,
        force_detach: Optional[bool] = None,
        instance_id: Optional[str] = None,
        skip_destroy: Optional[bool] = None,
        volume_id: Optional[str] = None) -> VolumeAttachment
func GetVolumeAttachment(ctx *Context, name string, id IDInput, state *VolumeAttachmentState, opts ...ResourceOption) (*VolumeAttachment, error)
public static VolumeAttachment Get(string name, Input<string> id, VolumeAttachmentState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

DeviceName string
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.
ForceDetach bool
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.
InstanceId string
ID of the Instance to attach to
SkipDestroy bool
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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
VolumeId string
ID of the Volume to be attached
DeviceName string
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.
ForceDetach bool
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.
InstanceId string
ID of the Instance to attach to
SkipDestroy bool
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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
VolumeId string
ID of the Volume to be attached
deviceName string
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.
forceDetach 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.
instanceId string
ID of the Instance to attach to
skipDestroy 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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
volumeId string
ID of the Volume to be attached
device_name str
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.
force_detach bool
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.
instance_id str
ID of the Instance to attach to
skip_destroy bool
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 this provider state. This is useful when destroying an instance which has volumes created by some other means attached.
volume_id str
ID of the Volume to be attached

Import

EBS Volume Attachments can be imported using DEVICE_NAME:VOLUME_ID:INSTANCE_ID, e.g.

 $ pulumi import aws:ec2/volumeAttachment:VolumeAttachment example /dev/sdh:vol-049df61146c4d7901:i-12345678

[1]https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names [2]https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names [3]https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.