DiskResourcePolicyAttachment class

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",
});
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")
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",
    });

});
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 {
		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
	})
}
pulumi {
  required_providers {
    gcp = {
      source = "pulumi/gcp"
    }
  }
}

data "gcp_compute_getimage" "myImage" {
  family  = "debian-11"
  project = "debian-cloud"
}

resource "gcp_compute_diskresourcepolicyattachment" "attachment" {
  name = gcp_compute_resourcepolicy.policy.name
  disk = gcp_compute_disk.ssd.name
  zone = "us-central1-a"
}
resource "gcp_compute_disk" "ssd" {
  name  = "my-disk"
  image = data.gcp_compute_getimage.myImage.self_link
  size  = 50
  type  = "pd-ssd"
  zone  = "us-central1-a"
}
resource "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"
      }
    }
  }
}
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.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) {
        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.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());

    }
}
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

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}}
$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default {{project}}/{{zone}}/{{disk}}/{{name}}
$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default {{zone}}/{{disk}}/{{name}}
$ pulumi import gcp:compute/diskResourcePolicyAttachment:DiskResourcePolicyAttachment default {{disk}}/{{name}}

Constructors

DiskResourcePolicyAttachment(String name, {DiskResourcePolicyAttachmentArgs? args, CustomResourceOptions? options})
Creates a new DiskResourcePolicyAttachment. name The Pulumi resource name. args Arguments used to configure this DiskResourcePolicyAttachment. The set of arguments for DiskResourcePolicyAttachment. options Resource options controlling this resource's behavior.
DiskResourcePolicyAttachment.reference(String urn)
Creates a typed reference to an existing DiskResourcePolicyAttachment 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
disk ↔ Output<String>
The name of the disk in which the resource policies are attached to.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
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
name ↔ Output<String>
The resource policy to be attached to the disk for scheduling snapshot creation. Do not specify the self link.
latefinal
project ↔ Output<String>
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
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>
A reference to the zone where the disk resides.
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, {DiskResourcePolicyAttachmentState? state, CustomResourceOptions? options}) → DiskResourcePolicyAttachment
Gets an existing DiskResourcePolicyAttachment resource's state with the given name and id.