VolumeAttachmentArgs

data class VolumeAttachmentArgs(val deviceName: Output<String>? = null, val forceDetach: Output<Boolean>? = null, val instanceId: Output<String>? = null, val skipDestroy: Output<Boolean>? = null, val stopInstanceBeforeDetaching: Output<Boolean>? = null, val volumeId: Output<String>? = null) : ConvertibleToJava<VolumeAttachmentArgs>

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.ec2.VolumeAttachment resources for a given instance.

Example Usage

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: aws.ec2.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("ebs_att", {
deviceName: "/dev/sdh",
volumeId: example.id,
instanceId: web.id,
});
import pulumi
import pulumi_aws as aws
web = aws.ec2.Instance("web",
ami="ami-21f78e11",
availability_zone="us-west-2a",
instance_type=aws.ec2.InstanceType.T2_MICRO,
tags={
"Name": "HelloWorld",
})
example = aws.ebs.Volume("example",
availability_zone="us-west-2a",
size=1)
ebs_att = aws.ec2.VolumeAttachment("ebs_att",
device_name="/dev/sdh",
volume_id=example.id,
instance_id=web.id)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var web = new Aws.Ec2.Instance("web", new()
{
Ami = "ami-21f78e11",
AvailabilityZone = "us-west-2a",
InstanceType = Aws.Ec2.InstanceType.T2_Micro,
Tags =
{
{ "Name", "HelloWorld" },
},
});
var example = new Aws.Ebs.Volume("example", new()
{
AvailabilityZone = "us-west-2a",
Size = 1,
});
var ebsAtt = new Aws.Ec2.VolumeAttachment("ebs_att", new()
{
DeviceName = "/dev/sdh",
VolumeId = example.Id,
InstanceId = web.Id,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ebs"
"github.com/pulumi/pulumi-aws/sdk/v6/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(ec2.InstanceType_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, "ebs_att", &ec2.VolumeAttachmentArgs{
DeviceName: pulumi.String("/dev/sdh"),
VolumeId: example.ID(),
InstanceId: web.ID(),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.ec2.InstanceArgs;
import com.pulumi.aws.ebs.Volume;
import com.pulumi.aws.ebs.VolumeArgs;
import com.pulumi.aws.ec2.VolumeAttachment;
import com.pulumi.aws.ec2.VolumeAttachmentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var web = new Instance("web", InstanceArgs.builder()
.ami("ami-21f78e11")
.availabilityZone("us-west-2a")
.instanceType("t2.micro")
.tags(Map.of("Name", "HelloWorld"))
.build());
var example = new Volume("example", VolumeArgs.builder()
.availabilityZone("us-west-2a")
.size(1)
.build());
var ebsAtt = new VolumeAttachment("ebsAtt", VolumeAttachmentArgs.builder()
.deviceName("/dev/sdh")
.volumeId(example.id())
.instanceId(web.id())
.build());
}
}
resources:
ebsAtt:
type: aws:ec2:VolumeAttachment
name: ebs_att
properties:
deviceName: /dev/sdh
volumeId: ${example.id}
instanceId: ${web.id}
web:
type: aws:ec2:Instance
properties:
ami: ami-21f78e11
availabilityZone: us-west-2a
instanceType: t2.micro
tags:
Name: HelloWorld
example:
type: aws:ebs:Volume
properties:
availabilityZone: us-west-2a
size: 1

Import

Using pulumi import, import EBS Volume Attachments using DEVICE_NAME:VOLUME_ID:INSTANCE_ID. For example:

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

Constructors

Link copied to clipboard
constructor(deviceName: Output<String>? = null, forceDetach: Output<Boolean>? = null, instanceId: Output<String>? = null, skipDestroy: Output<Boolean>? = null, stopInstanceBeforeDetaching: Output<Boolean>? = null, volumeId: Output<String>? = null)

Properties

Link copied to clipboard
val deviceName: Output<String>? = null

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.

Link copied to clipboard
val forceDetach: Output<Boolean>? = null

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.

Link copied to clipboard
val instanceId: Output<String>? = null

ID of the Instance to attach to

Link copied to clipboard
val skipDestroy: Output<Boolean>? = null

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.

Link copied to clipboard

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.

Link copied to clipboard
val volumeId: Output<String>? = null

ID of the Volume to be attached

Functions

Link copied to clipboard
open override fun toJava(): VolumeAttachmentArgs