googleComputeAttachedDisk
Persistent disks can be attached to a compute instance using the attachedDisk
section within the compute instance configuration. However there may be situations where managing the attached disks via the compute instance config isn't preferable or possible, such as attaching dynamic numbers of disks using the count
variable.
To get more information about attaching disks, see:
Note: When using googleComputeAttachedDisk
you must use lifecycleIgnoreChanges = ["attachedDisk"]
on the googleComputeInstance
resource that has the disks attached. Otherwise the two resources will fight for control of the attached disk block.
Example Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeInstanceDefault = new google.computeInstance.ComputeInstance(
this,
"default",
{
boot_disk: [
{
initialize_params: [
{
image: "debian-cloud/debian-11",
},
],
},
],
machine_type: "e2-medium",
name: "attached-disk-instance",
network_interface: [
{
network: "default",
},
],
zone: "us-west1-a",
}
);
googleComputeInstanceDefault.addOverride("lifecycle", [
{
ignore_changes: ["${attached_disk}"],
},
]);
const googleComputeAttachedDiskDefault =
new google.computeAttachedDisk.ComputeAttachedDisk(this, "default_1", {
disk: "${google_compute_disk.default.id}",
instance: googleComputeInstanceDefault.id,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeAttachedDiskDefault.overrideLogicalId("default");
Argument Reference
The following arguments are supported:
-
instance
- (Required)name
orselfLink
of the compute instance that the disk will be attached to. If theselfLink
is provided thenzone
andproject
are extracted from the self link. If only the name is used thenzone
andproject
must be defined as properties on the resource or provider. -
disk
- (Required)name
orselfLink
of the disk that will be attached.
-
project
- (Optional) The project that the referenced compute instance is a part of. Ifinstance
is referenced by itsselfLink
the project defined in the link will take precedence. -
zone
- (Optional) The zone that the referenced compute instance is located within. Ifinstance
is referenced by itsselfLink
the zone defined in the link will take precedence. -
deviceName
- (Optional) Specifies a unique device name of your choice that is reflected into the /dev/disk/by-id/google-* tree of a Linux operating system running within the instance. This name can be used to reference the device for mounting, resizing, and so on, from within the instance.If not specified, the server chooses a default device name to apply to this disk, in the form persistent-disks-x, where x is a number assigned by Google Compute Engine.
-
mode
- (Optional) The mode in which to attach this disk, either READ_WRITE or READ_ONLY. If not specified, the default is to attach the disk in READ_WRITE mode.Possible values: "READ_ONLY" "READ_WRITE"
Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with formatprojects/{{project}}/zones/{{zone}}/disks/{{diskName}}
Timeouts
This resource provides the following Timeouts configuration options: configuration options:
create
- Default is 5 minutes.delete
- Default is 5 minutes.
Import
Attached Disk can be imported the following ways: