ucloud.DiskAttachment
Explore with Pulumi AI
Provides a Cloud Disk Attachment resource for attaching Cloud Disk to UHost Instance.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as ucloud from "@pulumi/ucloud";
const defaultZones = ucloud.getZones({});
const defaultImages = defaultZones.then(defaultZones => ucloud.getImages({
availabilityZone: defaultZones.zones?.[0]?.id,
nameRegex: "^CentOS 7.[1-2] 64",
imageType: "base",
}));
// Create cloud disk
const defaultDisk = new ucloud.Disk("defaultDisk", {
availabilityZone: defaultZones.then(defaultZones => defaultZones.zones?.[0]?.id),
diskSize: 10,
});
// Create a web server
const web = new ucloud.Instance("web", {
availabilityZone: defaultZones.then(defaultZones => defaultZones.zones?.[0]?.id),
instanceType: "n-basic-2",
imageId: defaultImages.then(defaultImages => defaultImages.images?.[0]?.id),
rootPassword: "wA1234567",
tag: "tf-example",
});
// attach cloud disk to instance
const defaultDiskAttachment = new ucloud.DiskAttachment("defaultDiskAttachment", {
availabilityZone: defaultZones.then(defaultZones => defaultZones.zones?.[0]?.id),
diskId: defaultDisk.diskId,
instanceId: web.instanceId,
stopInstanceBeforeDetaching: true,
});
import pulumi
import pulumi_ucloud as ucloud
default_zones = ucloud.get_zones()
default_images = ucloud.get_images(availability_zone=default_zones.zones[0].id,
name_regex="^CentOS 7.[1-2] 64",
image_type="base")
# Create cloud disk
default_disk = ucloud.Disk("defaultDisk",
availability_zone=default_zones.zones[0].id,
disk_size=10)
# Create a web server
web = ucloud.Instance("web",
availability_zone=default_zones.zones[0].id,
instance_type="n-basic-2",
image_id=default_images.images[0].id,
root_password="wA1234567",
tag="tf-example")
# attach cloud disk to instance
default_disk_attachment = ucloud.DiskAttachment("defaultDiskAttachment",
availability_zone=default_zones.zones[0].id,
disk_id=default_disk.disk_id,
instance_id=web.instance_id,
stop_instance_before_detaching=True)
package main
import (
"github.com/pulumi/pulumi-terraform-provider/sdks/go/ucloud/ucloud"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
defaultZones, err := ucloud.GetZones(ctx, &ucloud.GetZonesArgs{}, nil)
if err != nil {
return err
}
defaultImages, err := ucloud.GetImages(ctx, &ucloud.GetImagesArgs{
AvailabilityZone: pulumi.StringRef(defaultZones.Zones[0].Id),
NameRegex: pulumi.StringRef("^CentOS 7.[1-2] 64"),
ImageType: pulumi.StringRef("base"),
}, nil)
if err != nil {
return err
}
// Create cloud disk
defaultDisk, err := ucloud.NewDisk(ctx, "defaultDisk", &ucloud.DiskArgs{
AvailabilityZone: pulumi.String(defaultZones.Zones[0].Id),
DiskSize: pulumi.Float64(10),
})
if err != nil {
return err
}
// Create a web server
web, err := ucloud.NewInstance(ctx, "web", &ucloud.InstanceArgs{
AvailabilityZone: pulumi.String(defaultZones.Zones[0].Id),
InstanceType: pulumi.String("n-basic-2"),
ImageId: pulumi.String(defaultImages.Images[0].Id),
RootPassword: pulumi.String("wA1234567"),
Tag: pulumi.String("tf-example"),
})
if err != nil {
return err
}
// attach cloud disk to instance
_, err = ucloud.NewDiskAttachment(ctx, "defaultDiskAttachment", &ucloud.DiskAttachmentArgs{
AvailabilityZone: pulumi.String(defaultZones.Zones[0].Id),
DiskId: defaultDisk.DiskId,
InstanceId: web.InstanceId,
StopInstanceBeforeDetaching: pulumi.Bool(true),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Ucloud = Pulumi.Ucloud;
return await Deployment.RunAsync(() =>
{
var defaultZones = Ucloud.GetZones.Invoke();
var defaultImages = Ucloud.GetImages.Invoke(new()
{
AvailabilityZone = defaultZones.Apply(getZonesResult => getZonesResult.Zones[0]?.Id),
NameRegex = "^CentOS 7.[1-2] 64",
ImageType = "base",
});
// Create cloud disk
var defaultDisk = new Ucloud.Disk("defaultDisk", new()
{
AvailabilityZone = defaultZones.Apply(getZonesResult => getZonesResult.Zones[0]?.Id),
DiskSize = 10,
});
// Create a web server
var web = new Ucloud.Instance("web", new()
{
AvailabilityZone = defaultZones.Apply(getZonesResult => getZonesResult.Zones[0]?.Id),
InstanceType = "n-basic-2",
ImageId = defaultImages.Apply(getImagesResult => getImagesResult.Images[0]?.Id),
RootPassword = "wA1234567",
Tag = "tf-example",
});
// attach cloud disk to instance
var defaultDiskAttachment = new Ucloud.DiskAttachment("defaultDiskAttachment", new()
{
AvailabilityZone = defaultZones.Apply(getZonesResult => getZonesResult.Zones[0]?.Id),
DiskId = defaultDisk.DiskId,
InstanceId = web.InstanceId,
StopInstanceBeforeDetaching = true,
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.ucloud.UcloudFunctions;
import com.pulumi.ucloud.inputs.GetZonesArgs;
import com.pulumi.ucloud.inputs.GetImagesArgs;
import com.pulumi.ucloud.Disk;
import com.pulumi.ucloud.DiskArgs;
import com.pulumi.ucloud.Instance;
import com.pulumi.ucloud.InstanceArgs;
import com.pulumi.ucloud.DiskAttachment;
import com.pulumi.ucloud.DiskAttachmentArgs;
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) {
final var defaultZones = UcloudFunctions.getZones();
final var defaultImages = UcloudFunctions.getImages(GetImagesArgs.builder()
.availabilityZone(defaultZones.applyValue(getZonesResult -> getZonesResult.zones()[0].id()))
.nameRegex("^CentOS 7.[1-2] 64")
.imageType("base")
.build());
// Create cloud disk
var defaultDisk = new Disk("defaultDisk", DiskArgs.builder()
.availabilityZone(defaultZones.applyValue(getZonesResult -> getZonesResult.zones()[0].id()))
.diskSize(10)
.build());
// Create a web server
var web = new Instance("web", InstanceArgs.builder()
.availabilityZone(defaultZones.applyValue(getZonesResult -> getZonesResult.zones()[0].id()))
.instanceType("n-basic-2")
.imageId(defaultImages.applyValue(getImagesResult -> getImagesResult.images()[0].id()))
.rootPassword("wA1234567")
.tag("tf-example")
.build());
// attach cloud disk to instance
var defaultDiskAttachment = new DiskAttachment("defaultDiskAttachment", DiskAttachmentArgs.builder()
.availabilityZone(defaultZones.applyValue(getZonesResult -> getZonesResult.zones()[0].id()))
.diskId(defaultDisk.diskId())
.instanceId(web.instanceId())
.stopInstanceBeforeDetaching(true)
.build());
}
}
resources:
# Create cloud disk
defaultDisk:
type: ucloud:Disk
properties:
availabilityZone: ${defaultZones.zones[0].id}
diskSize: 10
# Create a web server
web:
type: ucloud:Instance
properties:
availabilityZone: ${defaultZones.zones[0].id}
instanceType: n-basic-2
imageId: ${defaultImages.images[0].id}
rootPassword: wA1234567
tag: tf-example
# attach cloud disk to instance
defaultDiskAttachment:
type: ucloud:DiskAttachment
properties:
availabilityZone: ${defaultZones.zones[0].id}
diskId: ${defaultDisk.diskId}
instanceId: ${web.instanceId}
stopInstanceBeforeDetaching: true
variables:
defaultZones:
fn::invoke:
function: ucloud:getZones
arguments: {}
defaultImages:
fn::invoke:
function: ucloud:getImages
arguments:
availabilityZone: ${defaultZones.zones[0].id}
nameRegex: ^CentOS 7.[1-2] 64
imageType: base
Create DiskAttachment Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new DiskAttachment(name: string, args: DiskAttachmentArgs, opts?: CustomResourceOptions);
@overload
def DiskAttachment(resource_name: str,
args: DiskAttachmentArgs,
opts: Optional[ResourceOptions] = None)
@overload
def DiskAttachment(resource_name: str,
opts: Optional[ResourceOptions] = None,
availability_zone: Optional[str] = None,
disk_id: Optional[str] = None,
instance_id: Optional[str] = None,
disk_attachment_id: Optional[str] = None,
stop_instance_before_detaching: Optional[bool] = None)
func NewDiskAttachment(ctx *Context, name string, args DiskAttachmentArgs, opts ...ResourceOption) (*DiskAttachment, error)
public DiskAttachment(string name, DiskAttachmentArgs args, CustomResourceOptions? opts = null)
public DiskAttachment(String name, DiskAttachmentArgs args)
public DiskAttachment(String name, DiskAttachmentArgs args, CustomResourceOptions options)
type: ucloud:DiskAttachment
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 DiskAttachmentArgs
- 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 DiskAttachmentArgs
- 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 DiskAttachmentArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args DiskAttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args DiskAttachmentArgs
- 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 diskAttachmentResource = new Ucloud.DiskAttachment("diskAttachmentResource", new()
{
AvailabilityZone = "string",
DiskId = "string",
InstanceId = "string",
DiskAttachmentId = "string",
StopInstanceBeforeDetaching = false,
});
example, err := ucloud.NewDiskAttachment(ctx, "diskAttachmentResource", &ucloud.DiskAttachmentArgs{
AvailabilityZone: pulumi.String("string"),
DiskId: pulumi.String("string"),
InstanceId: pulumi.String("string"),
DiskAttachmentId: pulumi.String("string"),
StopInstanceBeforeDetaching: pulumi.Bool(false),
})
var diskAttachmentResource = new DiskAttachment("diskAttachmentResource", DiskAttachmentArgs.builder()
.availabilityZone("string")
.diskId("string")
.instanceId("string")
.diskAttachmentId("string")
.stopInstanceBeforeDetaching(false)
.build());
disk_attachment_resource = ucloud.DiskAttachment("diskAttachmentResource",
availability_zone="string",
disk_id="string",
instance_id="string",
disk_attachment_id="string",
stop_instance_before_detaching=False)
const diskAttachmentResource = new ucloud.DiskAttachment("diskAttachmentResource", {
availabilityZone: "string",
diskId: "string",
instanceId: "string",
diskAttachmentId: "string",
stopInstanceBeforeDetaching: false,
});
type: ucloud:DiskAttachment
properties:
availabilityZone: string
diskAttachmentId: string
diskId: string
instanceId: string
stopInstanceBeforeDetaching: false
DiskAttachment 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 DiskAttachment resource accepts the following input properties:
- Availability
Zone string - The Zone to attach the disk in.
- Disk
Id string - The ID of disk that needs to be attached
- Instance
Id string - The ID of instance.
- Disk
Attachment stringId - Stop
Instance boolBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- Availability
Zone string - The Zone to attach the disk in.
- Disk
Id string - The ID of disk that needs to be attached
- Instance
Id string - The ID of instance.
- Disk
Attachment stringId - Stop
Instance boolBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability
Zone String - The Zone to attach the disk in.
- disk
Id String - The ID of disk that needs to be attached
- instance
Id String - The ID of instance.
- disk
Attachment StringId - stop
Instance BooleanBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability
Zone string - The Zone to attach the disk in.
- disk
Id string - The ID of disk that needs to be attached
- instance
Id string - The ID of instance.
- disk
Attachment stringId - stop
Instance booleanBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability_
zone str - The Zone to attach the disk in.
- disk_
id str - The ID of disk that needs to be attached
- instance_
id str - The ID of instance.
- disk_
attachment_ strid - stop_
instance_ boolbefore_ detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability
Zone String - The Zone to attach the disk in.
- disk
Id String - The ID of disk that needs to be attached
- instance
Id String - The ID of instance.
- disk
Attachment StringId - stop
Instance BooleanBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
Outputs
All input properties are implicitly available as output properties. Additionally, the DiskAttachment resource produces the following output properties:
- Device
Name string - The device name to expose to the instance, for example
vdb
. - Id string
- The provider-assigned unique ID for this managed resource.
- Device
Name string - The device name to expose to the instance, for example
vdb
. - Id string
- The provider-assigned unique ID for this managed resource.
- device
Name String - The device name to expose to the instance, for example
vdb
. - id String
- The provider-assigned unique ID for this managed resource.
- device
Name string - The device name to expose to the instance, for example
vdb
. - id string
- The provider-assigned unique ID for this managed resource.
- device_
name str - The device name to expose to the instance, for example
vdb
. - id str
- The provider-assigned unique ID for this managed resource.
- device
Name String - The device name to expose to the instance, for example
vdb
. - id String
- The provider-assigned unique ID for this managed resource.
Look up Existing DiskAttachment Resource
Get an existing DiskAttachment 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?: DiskAttachmentState, opts?: CustomResourceOptions): DiskAttachment
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
availability_zone: Optional[str] = None,
device_name: Optional[str] = None,
disk_attachment_id: Optional[str] = None,
disk_id: Optional[str] = None,
instance_id: Optional[str] = None,
stop_instance_before_detaching: Optional[bool] = None) -> DiskAttachment
func GetDiskAttachment(ctx *Context, name string, id IDInput, state *DiskAttachmentState, opts ...ResourceOption) (*DiskAttachment, error)
public static DiskAttachment Get(string name, Input<string> id, DiskAttachmentState? state, CustomResourceOptions? opts = null)
public static DiskAttachment get(String name, Output<String> id, DiskAttachmentState state, CustomResourceOptions options)
resources: _: type: ucloud:DiskAttachment get: id: ${id}
- 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.
- Availability
Zone string - The Zone to attach the disk in.
- Device
Name string - The device name to expose to the instance, for example
vdb
. - Disk
Attachment stringId - Disk
Id string - The ID of disk that needs to be attached
- Instance
Id string - The ID of instance.
- Stop
Instance boolBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- Availability
Zone string - The Zone to attach the disk in.
- Device
Name string - The device name to expose to the instance, for example
vdb
. - Disk
Attachment stringId - Disk
Id string - The ID of disk that needs to be attached
- Instance
Id string - The ID of instance.
- Stop
Instance boolBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability
Zone String - The Zone to attach the disk in.
- device
Name String - The device name to expose to the instance, for example
vdb
. - disk
Attachment StringId - disk
Id String - The ID of disk that needs to be attached
- instance
Id String - The ID of instance.
- stop
Instance BooleanBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability
Zone string - The Zone to attach the disk in.
- device
Name string - The device name to expose to the instance, for example
vdb
. - disk
Attachment stringId - disk
Id string - The ID of disk that needs to be attached
- instance
Id string - The ID of instance.
- stop
Instance booleanBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability_
zone str - The Zone to attach the disk in.
- device_
name str - The device name to expose to the instance, for example
vdb
. - disk_
attachment_ strid - disk_
id str - The ID of disk that needs to be attached
- instance_
id str - The ID of instance.
- stop_
instance_ boolbefore_ detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
- availability
Zone String - The Zone to attach the disk in.
- device
Name String - The device name to expose to the instance, for example
vdb
. - disk
Attachment StringId - disk
Id String - The ID of disk that needs to be attached
- instance
Id String - The ID of instance.
- stop
Instance BooleanBefore Detaching - Set this to true to ensure that the target instance is stopped before trying to detach the volume.
Package Details
- Repository
- ucloud ucloud/terraform-provider-ucloud
- License
- Notes
- This Pulumi package is based on the
ucloud
Terraform Provider.