gcp.compute.AttachedDisk

Persistent disks can be attached to a compute instance using the attached_disk 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 gcp.compute.AttachedDisk you must use lifecycle.ignore_changes = ["attached_disk"] on the gcp.compute.Instance resource that has the disks attached. Otherwise the two resources will fight for control of the attached disk block.

Example Usage

using System.Collections.Generic;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var defaultInstance = new Gcp.Compute.Instance("defaultInstance", new()
    {
        MachineType = "e2-medium",
        Zone = "us-west1-a",
        BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
        {
            InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
            {
                Image = "debian-cloud/debian-11",
            },
        },
        NetworkInterfaces = new[]
        {
            new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
            {
                Network = "default",
            },
        },
    });

    var defaultAttachedDisk = new Gcp.Compute.AttachedDisk("defaultAttachedDisk", new()
    {
        Disk = google_compute_disk.Default.Id,
        Instance = defaultInstance.Id,
    });

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		defaultInstance, err := compute.NewInstance(ctx, "defaultInstance", &compute.InstanceArgs{
			MachineType: pulumi.String("e2-medium"),
			Zone:        pulumi.String("us-west1-a"),
			BootDisk: &compute.InstanceBootDiskArgs{
				InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
					Image: pulumi.String("debian-cloud/debian-11"),
				},
			},
			NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
				&compute.InstanceNetworkInterfaceArgs{
					Network: pulumi.String("default"),
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = compute.NewAttachedDisk(ctx, "defaultAttachedDisk", &compute.AttachedDiskArgs{
			Disk:     pulumi.Any(google_compute_disk.Default.Id),
			Instance: defaultInstance.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.gcp.compute.Instance;
import com.pulumi.gcp.compute.InstanceArgs;
import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
import com.pulumi.gcp.compute.AttachedDisk;
import com.pulumi.gcp.compute.AttachedDiskArgs;
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 defaultInstance = new Instance("defaultInstance", InstanceArgs.builder()        
            .machineType("e2-medium")
            .zone("us-west1-a")
            .bootDisk(InstanceBootDiskArgs.builder()
                .initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
                    .image("debian-cloud/debian-11")
                    .build())
                .build())
            .networkInterfaces(InstanceNetworkInterfaceArgs.builder()
                .network("default")
                .build())
            .build());

        var defaultAttachedDisk = new AttachedDisk("defaultAttachedDisk", AttachedDiskArgs.builder()        
            .disk(google_compute_disk.default().id())
            .instance(defaultInstance.id())
            .build());

    }
}
import pulumi
import pulumi_gcp as gcp

default_instance = gcp.compute.Instance("defaultInstance",
    machine_type="e2-medium",
    zone="us-west1-a",
    boot_disk=gcp.compute.InstanceBootDiskArgs(
        initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
            image="debian-cloud/debian-11",
        ),
    ),
    network_interfaces=[gcp.compute.InstanceNetworkInterfaceArgs(
        network="default",
    )])
default_attached_disk = gcp.compute.AttachedDisk("defaultAttachedDisk",
    disk=google_compute_disk["default"]["id"],
    instance=default_instance.id)
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const defaultInstance = new gcp.compute.Instance("defaultInstance", {
    machineType: "e2-medium",
    zone: "us-west1-a",
    bootDisk: {
        initializeParams: {
            image: "debian-cloud/debian-11",
        },
    },
    networkInterfaces: [{
        network: "default",
    }],
});
const defaultAttachedDisk = new gcp.compute.AttachedDisk("defaultAttachedDisk", {
    disk: google_compute_disk["default"].id,
    instance: defaultInstance.id,
});
resources:
  defaultAttachedDisk:
    type: gcp:compute:AttachedDisk
    properties:
      disk: ${google_compute_disk.default.id}
      instance: ${defaultInstance.id}
  defaultInstance:
    type: gcp:compute:Instance
    properties:
      machineType: e2-medium
      zone: us-west1-a
      bootDisk:
        initializeParams:
          image: debian-cloud/debian-11
      networkInterfaces:
        - network: default

Create AttachedDisk Resource

new AttachedDisk(name: string, args: AttachedDiskArgs, opts?: CustomResourceOptions);
@overload
def AttachedDisk(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 device_name: Optional[str] = None,
                 disk: Optional[str] = None,
                 instance: Optional[str] = None,
                 mode: Optional[str] = None,
                 project: Optional[str] = None,
                 zone: Optional[str] = None)
@overload
def AttachedDisk(resource_name: str,
                 args: AttachedDiskArgs,
                 opts: Optional[ResourceOptions] = None)
func NewAttachedDisk(ctx *Context, name string, args AttachedDiskArgs, opts ...ResourceOption) (*AttachedDisk, error)
public AttachedDisk(string name, AttachedDiskArgs args, CustomResourceOptions? opts = null)
public AttachedDisk(String name, AttachedDiskArgs args)
public AttachedDisk(String name, AttachedDiskArgs args, CustomResourceOptions options)
type: gcp:compute:AttachedDisk
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args AttachedDiskArgs
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 AttachedDiskArgs
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 AttachedDiskArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args AttachedDiskArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args AttachedDiskArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

AttachedDisk Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The AttachedDisk resource accepts the following input properties:

Disk string

name or self_link of the disk that will be attached.

Instance string

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

DeviceName string

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.

Mode string

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.

Project string

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

Zone string

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

Disk string

name or self_link of the disk that will be attached.

Instance string

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

DeviceName string

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.

Mode string

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.

Project string

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

Zone string

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

disk String

name or self_link of the disk that will be attached.

instance String

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

deviceName String

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.

mode String

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.

project String

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone String

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

disk string

name or self_link of the disk that will be attached.

instance string

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

deviceName string

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.

mode string

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.

project string

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone string

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

disk str

name or self_link of the disk that will be attached.

instance str

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

device_name str

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.

mode str

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.

project str

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone str

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

disk String

name or self_link of the disk that will be attached.

instance String

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

deviceName String

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.

mode String

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.

project String

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone String

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

Outputs

All input properties are implicitly available as output properties. Additionally, the AttachedDisk 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 AttachedDisk Resource

Get an existing AttachedDisk 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?: AttachedDiskState, opts?: CustomResourceOptions): AttachedDisk
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        device_name: Optional[str] = None,
        disk: Optional[str] = None,
        instance: Optional[str] = None,
        mode: Optional[str] = None,
        project: Optional[str] = None,
        zone: Optional[str] = None) -> AttachedDisk
func GetAttachedDisk(ctx *Context, name string, id IDInput, state *AttachedDiskState, opts ...ResourceOption) (*AttachedDisk, error)
public static AttachedDisk Get(string name, Input<string> id, AttachedDiskState? state, CustomResourceOptions? opts = null)
public static AttachedDisk get(String name, Output<String> id, AttachedDiskState 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.
The following state arguments are supported:
DeviceName string

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.

Disk string

name or self_link of the disk that will be attached.

Instance string

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

Mode string

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.

Project string

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

Zone string

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

DeviceName string

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.

Disk string

name or self_link of the disk that will be attached.

Instance string

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

Mode string

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.

Project string

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

Zone string

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

deviceName String

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.

disk String

name or self_link of the disk that will be attached.

instance String

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

mode String

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.

project String

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone String

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

deviceName string

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.

disk string

name or self_link of the disk that will be attached.

instance string

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

mode string

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.

project string

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone string

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

device_name str

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.

disk str

name or self_link of the disk that will be attached.

instance str

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

mode str

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.

project str

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone str

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

deviceName String

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.

disk String

name or self_link of the disk that will be attached.

instance String

name or self_link of the compute instance that the disk will be attached to. If the self_link is provided then zone and project are extracted from the self link. If only the name is used then zone and project must be defined as properties on the resource or provider.

mode String

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.

project String

The project that the referenced compute instance is a part of. If instance is referenced by its self_link the project defined in the link will take precedence.

zone String

The zone that the referenced compute instance is located within. If instance is referenced by its self_link the zone defined in the link will take precedence.

Import

Attached Disk can be imported the following ways

 $ pulumi import gcp:compute/attachedDisk:AttachedDisk default projects/{{project}}/zones/{{zone}}/instances/{{instance.name}}/{{disk.name}}
 $ pulumi import gcp:compute/attachedDisk:AttachedDisk default {{project}}/{{zone}}/{{instance.name}}/{{disk.name}}

Package Details

Repository
Google Cloud (GCP) Classic pulumi/pulumi-gcp
License
Apache-2.0
Notes

This Pulumi package is based on the google-beta Terraform Provider.