AttachedDisk class
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:
- API documentation
- How-to Guides
- Adding a persistent disk
Note: When using gcp.compute.AttachedDisk you must use lifecycle.ignore_changes = ["attachedDisk"] 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
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const defaultInstance = new gcp.compute.Instance("default", {
name: "attached-disk-instance",
machineType: "e2-medium",
zone: "us-west1-a",
bootDisk: {
initializeParams: {
image: "debian-cloud/debian-11",
},
},
networkInterfaces: [{
network: "default",
}],
});
const _default = new gcp.compute.AttachedDisk("default", {
disk: defaultGoogleComputeDisk.id,
instance: defaultInstance.id,
});
import pulumi
import pulumi_gcp as gcp
default_instance = gcp.compute.Instance("default",
name="attached-disk-instance",
machine_type="e2-medium",
zone="us-west1-a",
boot_disk={
"initialize_params": {
"image": "debian-cloud/debian-11",
},
},
network_interfaces=[{
"network": "default",
}])
default = gcp.compute.AttachedDisk("default",
disk=default_google_compute_disk["id"],
instance=default_instance.id)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var defaultInstance = new Gcp.Compute.Instance("default", new()
{
Name = "attached-disk-instance",
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 @default = new Gcp.Compute.AttachedDisk("default", new()
{
Disk = defaultGoogleComputeDisk.Id,
Instance = defaultInstance.Id,
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/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, "default", &compute.InstanceArgs{
Name: pulumi.String("attached-disk-instance"),
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, "default", &compute.AttachedDiskArgs{
Disk: pulumi.Any(defaultGoogleComputeDisk.Id),
Instance: defaultInstance.ID().ToIDOutput().ToStringOutput(),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
gcp = {
source = "pulumi/gcp"
}
}
}
resource "gcp_compute_attacheddisk" "default" {
disk = defaultGoogleComputeDisk.id
instance = gcp_compute_instance.default.id
}
resource "gcp_compute_instance" "default" {
name = "attached-disk-instance"
machine_type = "e2-medium"
zone = "us-west1-a"
boot_disk = {
initialize_params = {
image = "debian-cloud/debian-11"
}
}
network_interfaces {
network = "default"
}
}
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.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 defaultInstance = new Instance("defaultInstance", InstanceArgs.builder()
.name("attached-disk-instance")
.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 default_ = new AttachedDisk("default", AttachedDiskArgs.builder()
.disk(defaultGoogleComputeDisk.get("id"))
.instance(defaultInstance.id())
.build());
}
}
resources:
default:
type: gcp:compute:AttachedDisk
properties:
disk: ${defaultGoogleComputeDisk.id}
instance: ${defaultInstance.id}
defaultInstance:
type: gcp:compute:Instance
name: default
properties:
name: attached-disk-instance
machineType: e2-medium
zone: us-west1-a
bootDisk:
initializeParams:
image: debian-cloud/debian-11
networkInterfaces:
- network: default
Import
Attached Disk can be imported the following ways:
projects/{{project}}/zones/{{zone}}/instances/{{instance.name}}/{{disk.name}}{{project}}/{{zone}}/{{instance.name}}/{{disk.name}}
When using the pulumi import command, Attached Disk can be imported using one of the formats above. For example:
$ 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}}
Constructors
- AttachedDisk(String name, {AttachedDiskArgs? args, CustomResourceOptions? options})
-
Creates a new AttachedDisk.
nameThe Pulumi resource name.argsArguments used to configure this AttachedDisk. The set of arguments for AttachedDisk.optionsResource options controlling this resource's behavior. - AttachedDisk.reference(String urn)
- Creates a typed reference to an existing AttachedDisk resource.
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
deletionPolicy
↔ Output<
String> -
Whether Terraform will be prevented from destroying the resource. Defaults to "DELETE".
When a 'terraform destroy' or 'pulumi up' would delete the resource,
the command will fail if this field is set to "PREVENT" in Terraform state.
When set to "ABANDON", the command will remove the resource from Terraform
management without updating or deleting the resource in the API.
When set to "DELETE", deleting the resource is allowed.
latefinal
-
deviceName
↔ Output<
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.
latefinal
-
disk
↔ Output<
String> -
nameorselfLinkof the disk that will be attached.latefinal - hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
-
instance
↔ Output<
String> -
nameorselfLinkof the compute instance that the disk will be attached to. If theselfLinkis provided thenzoneandprojectare extracted from the self link. If only the name is used thenzoneandprojectmust be defined as properties on the resource or provider.latefinal -
interface
↔ Output<
String?> -
The disk interface used for attaching this disk.
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
-
mode
↔ Output<
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.
latefinal
-
project
↔ Output<
String> -
The project that the referenced compute instance is a part of. If
instanceis referenced by itsselfLinkthe project defined in the link will take precedence.latefinal -
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
zone
↔ Output<
String> -
The zone that the referenced compute instance is located within. If
instanceis referenced by itsselfLinkthe zone defined in the link will take precedence.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, {AttachedDiskState? state, CustomResourceOptions? options}) → AttachedDisk -
Gets an existing AttachedDisk resource's state with the given
nameandid.