1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. compute
  5. DiskResourcePolicyAttachment
Google Cloud v8.25.0 published on Thursday, Apr 3, 2025 by Pulumi

gcp.compute.DiskResourcePolicyAttachment

Explore with Pulumi AI

Adds existing resource policies to a disk. You can only add one policy which will be applied to this disk for scheduling snapshot creation.

Note: This resource does not support regional disks (gcp.compute.RegionDisk). For regional disks, please refer to the gcp.compute.RegionDiskResourcePolicyAttachment resource.

Example Usage

Disk Resource Policy Attachment Basic

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const myImage = gcp.compute.getImage({
    family: "debian-11",
    project: "debian-cloud",
});
const ssd = new gcp.compute.Disk("ssd", {
    name: "my-disk",
    image: myImage.then(myImage => myImage.selfLink),
    size: 50,
    type: "pd-ssd",
    zone: "us-central1-a",
});
const policy = new gcp.compute.ResourcePolicy("policy", {
    name: "my-resource-policy",
    region: "us-central1",
    snapshotSchedulePolicy: {
        schedule: {
            dailySchedule: {
                daysInCycle: 1,
                startTime: "04:00",
            },
        },
    },
});
const attachment = new gcp.compute.DiskResourcePolicyAttachment("attachment", {
    name: policy.name,
    disk: ssd.name,
    zone: "us-central1-a",
});
Copy
import pulumi
import pulumi_gcp as gcp

my_image = gcp.compute.get_image(family="debian-11",
    project="debian-cloud")
ssd = gcp.compute.Disk("ssd",
    name="my-disk",
    image=my_image.self_link,
    size=50,
    type="pd-ssd",
    zone="us-central1-a")
policy = gcp.compute.ResourcePolicy("policy",
    name="my-resource-policy",
    region="us-central1",
    snapshot_schedule_policy={
        "schedule": {
            "daily_schedule": {
                "days_in_cycle": 1,
                "start_time": "04:00",
            },
        },
    })
attachment = gcp.compute.DiskResourcePolicyAttachment("attachment",
    name=policy.name,
    disk=ssd.name,
    zone="us-central1-a")
Copy
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		myImage, err := compute.LookupImage(ctx, &compute.LookupImageArgs{
			Family:  pulumi.StringRef("debian-11"),
			Project: pulumi.StringRef("debian-cloud"),
		}, nil)
		if err != nil {
			return err
		}
		ssd, err := compute.NewDisk(ctx, "ssd", &compute.DiskArgs{
			Name:  pulumi.String("my-disk"),
			Image: pulumi.String(myImage.SelfLink),
			Size:  pulumi.Int(50),
			Type:  pulumi.String("pd-ssd"),
			Zone:  pulumi.String("us-central1-a"),
		})
		if err != nil {
			return err
		}
		policy, err := compute.NewResourcePolicy(ctx, "policy", &compute.ResourcePolicyArgs{
			Name:   pulumi.String("my-resource-policy"),
			Region: pulumi.String("us-central1"),
			SnapshotSchedulePolicy: &compute.ResourcePolicySnapshotSchedulePolicyArgs{
				Schedule: &compute.ResourcePolicySnapshotSchedulePolicyScheduleArgs{
					DailySchedule: &compute.ResourcePolicySnapshotSchedulePolicyScheduleDailyScheduleArgs{
						DaysInCycle: pulumi.Int(1),
						StartTime:   pulumi.String("04:00"),
					},
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = compute.NewDiskResourcePolicyAttachment(ctx, "attachment", &compute.DiskResourcePolicyAttachmentArgs{
			Name: policy.Name,
			Disk: ssd.Name,
			Zone: pulumi.String("us-central1-a"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var myImage = Gcp.Compute.GetImage.Invoke(new()
    {
        Family = "debian-11",
        Project = "debian-cloud",
    });

    var ssd = new Gcp.Compute.Disk("ssd", new()
    {
        Name = "my-disk",
        Image = myImage.Apply(getImageResult => getImageResult.SelfLink),
        Size = 50,
        Type = "pd-ssd",
        Zone = "us-central1-a",
    });

    var policy = new Gcp.Compute.ResourcePolicy("policy", new()
    {
        Name = "my-resource-policy",
        Region = "us-central1",
        SnapshotSchedulePolicy = new Gcp.Compute.Inputs.ResourcePolicySnapshotSchedulePolicyArgs
        {
            Schedule = new Gcp.Compute.Inputs.ResourcePolicySnapshotSchedulePolicyScheduleArgs
            {
                DailySchedule = new Gcp.Compute.Inputs.ResourcePolicySnapshotSchedulePolicyScheduleDailyScheduleArgs
                {
                    DaysInCycle = 1,
                    StartTime = "04:00",
                },
            },
        },
    });

    var attachment = new Gcp.Compute.DiskResourcePolicyAttachment("attachment", new()
    {
        Name = policy.Name,
        Disk = ssd.Name,
        Zone = "us-central1-a",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetImageArgs;
import com.pulumi.gcp.compute.Disk;
import com.pulumi.gcp.compute.DiskArgs;
import com.pulumi.gcp.compute.ResourcePolicy;
import com.pulumi.gcp.compute.ResourcePolicyArgs;
import com.pulumi.gcp.compute.inputs.ResourcePolicySnapshotSchedulePolicyArgs;
import com.pulumi.gcp.compute.inputs.ResourcePolicySnapshotSchedulePolicyScheduleArgs;
import com.pulumi.gcp.compute.inputs.ResourcePolicySnapshotSchedulePolicyScheduleDailyScheduleArgs;
import com.pulumi.gcp.compute.DiskResourcePolicyAttachment;
import com.pulumi.gcp.compute.DiskResourcePolicyAttachmentArgs;
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 myImage = ComputeFunctions.getImage(GetImageArgs.builder()
            .family("debian-11")
            .project("debian-cloud")
            .build());

        var ssd = new Disk("ssd", DiskArgs.builder()
            .name("my-disk")
            .image(myImage.applyValue(getImageResult -> getImageResult.selfLink()))
            .size(50)
            .type("pd-ssd")
            .zone("us-central1-a")
            .build());

        var policy = new ResourcePolicy("policy", ResourcePolicyArgs.builder()
            .name("my-resource-policy")
            .region("us-central1")
            .snapshotSchedulePolicy(ResourcePolicySnapshotSchedulePolicyArgs.builder()
                .schedule(ResourcePolicySnapshotSchedulePolicyScheduleArgs.builder()
                    .dailySchedule(ResourcePolicySnapshotSchedulePolicyScheduleDailyScheduleArgs.builder()
                        .daysInCycle(1)
                        .startTime("04:00")
                        .build())
                    .build())
                .build())
            .build());

        var attachment = new DiskResourcePolicyAttachment("attachment", DiskResourcePolicyAttachmentArgs.builder()
            .name(policy.name())
            .disk(ssd.name())
            .zone("us-central1-a")
            .build());

    }
}
Copy
resources:
  attachment:
    type: gcp:compute:DiskResourcePolicyAttachment
    properties:
      name: ${policy.name}
      disk: ${ssd.name}
      zone: us-central1-a
  ssd:
    type: gcp:compute:Disk
    properties:
      name: my-disk
      image: ${myImage.selfLink}
      size: 50
      type: pd-ssd
      zone: us-central1-a
  policy:
    type: gcp:compute:ResourcePolicy
    properties:
      name: my-resource-policy
      region: us-central1
      snapshotSchedulePolicy:
        schedule:
          dailySchedule:
            daysInCycle: 1
            startTime: 04:00
variables:
  myImage:
    fn::invoke:
      function: gcp:compute:getImage
      arguments:
        family: debian-11
        project: debian-cloud
Copy

Create DiskResourcePolicyAttachment Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new DiskResourcePolicyAttachment(name: string, args: DiskResourcePolicyAttachmentArgs, opts?: CustomResourceOptions);
@overload
def DiskResourcePolicyAttachment(resource_name: str,
                                 args: DiskResourcePolicyAttachmentArgs,
                                 opts: Optional[ResourceOptions] = None)

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

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. DiskResourcePolicyAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. DiskResourcePolicyAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. DiskResourcePolicyAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. DiskResourcePolicyAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. DiskResourcePolicyAttachmentArgs
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 diskResourcePolicyAttachmentResource = new Gcp.Compute.DiskResourcePolicyAttachment("diskResourcePolicyAttachmentResource", new()
{
    Disk = "string",
    Name = "string",
    Project = "string",
    Zone = "string",
});
Copy
example, err := compute.NewDiskResourcePolicyAttachment(ctx, "diskResourcePolicyAttachmentResource", &compute.DiskResourcePolicyAttachmentArgs{
	Disk:    pulumi.String("string"),
	Name:    pulumi.String("string"),
	Project: pulumi.String("string"),
	Zone:    pulumi.String("string"),
})
Copy
var diskResourcePolicyAttachmentResource = new DiskResourcePolicyAttachment("diskResourcePolicyAttachmentResource", DiskResourcePolicyAttachmentArgs.builder()
    .disk("string")
    .name("string")
    .project("string")
    .zone("string")
    .build());
Copy
disk_resource_policy_attachment_resource = gcp.compute.DiskResourcePolicyAttachment("diskResourcePolicyAttachmentResource",
    disk="string",
    name="string",
    project="string",
    zone="string")
Copy
const diskResourcePolicyAttachmentResource = new gcp.compute.DiskResourcePolicyAttachment("diskResourcePolicyAttachmentResource", {
    disk: "string",
    name: "string",
    project: "string",
    zone: "string",
});
Copy
type: gcp:compute:DiskResourcePolicyAttachment
properties:
    disk: string
    name: string
    project: string
    zone: string
Copy

DiskResourcePolicyAttachment 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 DiskResourcePolicyAttachment resource accepts the following input properties:

Disk
This property is required.
Changes to this property will trigger replacement.
string
The name of the disk in which the resource policies are attached to.


Name Changes to this property will trigger replacement. string
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
Project Changes to this property will trigger replacement. string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Zone Changes to this property will trigger replacement. string
A reference to the zone where the disk resides.
Disk
This property is required.
Changes to this property will trigger replacement.
string
The name of the disk in which the resource policies are attached to.


Name Changes to this property will trigger replacement. string
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
Project Changes to this property will trigger replacement. string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Zone Changes to this property will trigger replacement. string
A reference to the zone where the disk resides.
disk
This property is required.
Changes to this property will trigger replacement.
String
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. String
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. String
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. String
A reference to the zone where the disk resides.
disk
This property is required.
Changes to this property will trigger replacement.
string
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. string
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. string
A reference to the zone where the disk resides.
disk
This property is required.
Changes to this property will trigger replacement.
str
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. str
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. str
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. str
A reference to the zone where the disk resides.
disk
This property is required.
Changes to this property will trigger replacement.
String
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. String
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. String
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. String
A reference to the zone where the disk resides.

Outputs

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

Get an existing DiskResourcePolicyAttachment 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?: DiskResourcePolicyAttachmentState, opts?: CustomResourceOptions): DiskResourcePolicyAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        disk: Optional[str] = None,
        name: Optional[str] = None,
        project: Optional[str] = None,
        zone: Optional[str] = None) -> DiskResourcePolicyAttachment
func GetDiskResourcePolicyAttachment(ctx *Context, name string, id IDInput, state *DiskResourcePolicyAttachmentState, opts ...ResourceOption) (*DiskResourcePolicyAttachment, error)
public static DiskResourcePolicyAttachment Get(string name, Input<string> id, DiskResourcePolicyAttachmentState? state, CustomResourceOptions? opts = null)
public static DiskResourcePolicyAttachment get(String name, Output<String> id, DiskResourcePolicyAttachmentState state, CustomResourceOptions options)
resources:  _:    type: gcp:compute:DiskResourcePolicyAttachment    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
Disk Changes to this property will trigger replacement. string
The name of the disk in which the resource policies are attached to.


Name Changes to this property will trigger replacement. string
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
Project Changes to this property will trigger replacement. string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Zone Changes to this property will trigger replacement. string
A reference to the zone where the disk resides.
Disk Changes to this property will trigger replacement. string
The name of the disk in which the resource policies are attached to.


Name Changes to this property will trigger replacement. string
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
Project Changes to this property will trigger replacement. string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Zone Changes to this property will trigger replacement. string
A reference to the zone where the disk resides.
disk Changes to this property will trigger replacement. String
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. String
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. String
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. String
A reference to the zone where the disk resides.
disk Changes to this property will trigger replacement. string
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. string
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. string
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. string
A reference to the zone where the disk resides.
disk Changes to this property will trigger replacement. str
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. str
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. str
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. str
A reference to the zone where the disk resides.
disk Changes to this property will trigger replacement. String
The name of the disk in which the resource policies are attached to.


name Changes to this property will trigger replacement. String
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
project Changes to this property will trigger replacement. String
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
zone Changes to this property will trigger replacement. String
A reference to the zone where the disk resides.

Import

DiskResourcePolicyAttachment can be imported using any of these accepted formats:

  • projects/{{project}}/zones/{{zone}}/disks/{{disk}}/{{name}}

  • {{project}}/{{zone}}/{{disk}}/{{name}}

  • {{zone}}/{{disk}}/{{name}}

  • {{disk}}/{{name}}

When using the pulumi import command, DiskResourcePolicyAttachment can be imported using one of the formats above. For example:

$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default projects/{{project}}/zones/{{zone}}/disks/{{disk}}/{{name}}
Copy
$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default {{project}}/{{zone}}/{{disk}}/{{name}}
Copy
$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default {{zone}}/{{disk}}/{{name}}
Copy
$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default {{disk}}/{{name}}
Copy

To learn more about importing existing cloud resources, see Importing resources.

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.