VolumeAttachment class
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 ebsBlockDevice 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, ebsBlockDevice 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/v7/go/aws/ebs"
"github.com/pulumi/pulumi-aws/sdk/v7/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().ToIDOutput().ToStringOutput(),
InstanceId: web.ID().ToIDOutput().ToStringOutput(),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_ec2_volumeattachment" "ebs_att" {
device_name = "/dev/sdh"
volume_id = aws_ebs_volume.example.id
instance_id = aws_ec2_instance.web.id
}
resource "aws_ec2_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
}
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.ArrayList;
import java.util.Arrays;
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
Identity Schema
Required
deviceName(String) Device name exposed to the instance.instanceId(String) ID of the Instance.volumeId(String) ID of the Volume.
Optional
accountId(String) Account ID where this resource is managed.region(String) Region where this resource is managed.
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
- VolumeAttachment(String name, {VolumeAttachmentArgs? args, CustomResourceOptions? options})
-
Creates a new VolumeAttachment.
nameThe Pulumi resource name.argsArguments used to configure this VolumeAttachment. The set of arguments for VolumeAttachment.optionsResource options controlling this resource's behavior. - VolumeAttachment.reference(String urn)
- Creates a typed reference to an existing VolumeAttachment resource.
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
deviceName
↔ Output<
String> -
The device name to expose to the instance (for
example,
/dev/sdhorxvdh). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information.latefinal -
forceDetach
↔ Output<
bool?> -
Set to
trueif 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.latefinal - hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
-
instanceId
↔ Output<
String> -
ID of the Instance to attach to
latefinal
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
skipDestroy
↔ Output<
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.
latefinal
-
stopInstanceBeforeDetaching
↔ Output<
bool?> -
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.
latefinal
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
volumeId
↔ Output<
String> -
ID of the Volume to be attached
latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {VolumeAttachmentState? state, CustomResourceOptions? options}) → VolumeAttachment -
Gets an existing VolumeAttachment resource's state with the given
nameandid.