aws.ec2.VolumeAttachment
Explore with Pulumi AI
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 anaws.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 externalaws.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)
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
})
}
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 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
Create VolumeAttachment Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new VolumeAttachment(name: string, args: VolumeAttachmentArgs, opts?: CustomResourceOptions);
@overload
def VolumeAttachment(resource_name: str,
args: VolumeAttachmentArgs,
opts: Optional[ResourceOptions] = None)
@overload
def VolumeAttachment(resource_name: str,
opts: Optional[ResourceOptions] = None,
device_name: Optional[str] = None,
instance_id: Optional[str] = None,
volume_id: Optional[str] = None,
force_detach: Optional[bool] = None,
skip_destroy: Optional[bool] = None,
stop_instance_before_detaching: Optional[bool] = None)
func NewVolumeAttachment(ctx *Context, name string, args VolumeAttachmentArgs, opts ...ResourceOption) (*VolumeAttachment, error)
public VolumeAttachment(string name, VolumeAttachmentArgs args, CustomResourceOptions? opts = null)
public VolumeAttachment(String name, VolumeAttachmentArgs args)
public VolumeAttachment(String name, VolumeAttachmentArgs args, CustomResourceOptions options)
type: aws:ec2:VolumeAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- 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.
- name String
- The unique name of the resource.
- args VolumeAttachmentArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var volumeAttachmentResource = new Aws.Ec2.VolumeAttachment("volumeAttachmentResource", new()
{
DeviceName = "string",
InstanceId = "string",
VolumeId = "string",
ForceDetach = false,
SkipDestroy = false,
StopInstanceBeforeDetaching = false,
});
example, err := ec2.NewVolumeAttachment(ctx, "volumeAttachmentResource", &ec2.VolumeAttachmentArgs{
DeviceName: pulumi.String("string"),
InstanceId: pulumi.String("string"),
VolumeId: pulumi.String("string"),
ForceDetach: pulumi.Bool(false),
SkipDestroy: pulumi.Bool(false),
StopInstanceBeforeDetaching: pulumi.Bool(false),
})
var volumeAttachmentResource = new VolumeAttachment("volumeAttachmentResource", VolumeAttachmentArgs.builder()
.deviceName("string")
.instanceId("string")
.volumeId("string")
.forceDetach(false)
.skipDestroy(false)
.stopInstanceBeforeDetaching(false)
.build());
volume_attachment_resource = aws.ec2.VolumeAttachment("volumeAttachmentResource",
device_name="string",
instance_id="string",
volume_id="string",
force_detach=False,
skip_destroy=False,
stop_instance_before_detaching=False)
const volumeAttachmentResource = new aws.ec2.VolumeAttachment("volumeAttachmentResource", {
deviceName: "string",
instanceId: "string",
volumeId: "string",
forceDetach: false,
skipDestroy: false,
stopInstanceBeforeDetaching: false,
});
type: aws:ec2:VolumeAttachment
properties:
deviceName: string
forceDetach: false
instanceId: string
skipDestroy: false
stopInstanceBeforeDetaching: false
volumeId: string
VolumeAttachment Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The VolumeAttachment resource accepts the following input properties:
- Device
Name string - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - Instance
Id string - ID of the Instance to attach to
- Volume
Id string - 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.
- Stop
Instance boolBefore Detaching - 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.
- Device
Name string - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - Instance
Id string - ID of the Instance to attach to
- Volume
Id string - 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.
- Stop
Instance boolBefore Detaching - 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.
- device
Name String - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - instance
Id String - ID of the Instance to attach to
- volume
Id String - ID of the Volume to be attached
- force
Detach 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 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.
- stop
Instance BooleanBefore Detaching - 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.
- device
Name string - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - instance
Id string - ID of the Instance to attach to
- volume
Id string - ID of the Volume to be attached
- force
Detach 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 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.
- stop
Instance booleanBefore Detaching - 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.
- device_
name str - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). 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.
- stop_
instance_ boolbefore_ detaching - 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.
- device
Name String - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - instance
Id String - ID of the Instance to attach to
- volume
Id String - ID of the Volume to be attached
- force
Detach 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 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.
- stop
Instance BooleanBefore Detaching - 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.
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 string
- The provider-assigned unique ID for this managed resource.
- id str
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
Look up 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,
stop_instance_before_detaching: 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)
public static VolumeAttachment get(String name, Output<String> id, VolumeAttachmentState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- 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.
- 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.
- Device
Name string - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). 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 string - 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.
- Stop
Instance boolBefore Detaching - 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.
- Volume
Id string - ID of the Volume to be attached
- Device
Name string - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). 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 string - 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.
- Stop
Instance boolBefore Detaching - 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.
- Volume
Id string - ID of the Volume to be attached
- device
Name String - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - force
Detach 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. - instance
Id String - ID of the Instance to attach to
- skip
Destroy 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.
- stop
Instance BooleanBefore Detaching - 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.
- volume
Id String - ID of the Volume to be attached
- device
Name string - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - force
Detach 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. - instance
Id string - ID of the Instance to attach to
- skip
Destroy 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.
- stop
Instance booleanBefore Detaching - 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.
- volume
Id string - ID of the Volume to be attached
- device_
name str - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). 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.
- stop_
instance_ boolbefore_ detaching - 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.
- volume_
id str - ID of the Volume to be attached
- device
Name String - The device name to expose to the instance (for
example,
/dev/sdh
orxvdh
). See Device Naming on Linux Instances and Device Naming on Windows Instances for more information. - force
Detach 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. - instance
Id String - ID of the Instance to attach to
- skip
Destroy 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.
- stop
Instance BooleanBefore Detaching - 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.
- volume
Id String - ID of the Volume to be attached
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
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.