google_compute_resource_policy

A policy that can be attached to a resource to specify or schedule actions on that resource.

To get more information about ResourcePolicy, see:

Open in Cloud Shell

Example Usage - Resource Policy Basic

resource "google_compute_resource_policy" "foo" {
  name   = "gce-policy"
  region = "us-central1"
  snapshot_schedule_policy {
    schedule {
      daily_schedule {
        days_in_cycle = 1
        start_time    = "04:00"
      }
    }
  }
}
Open in Cloud Shell

Example Usage - Resource Policy Full

resource "google_compute_resource_policy" "bar" {
  name   = "gce-policy"
  region = "us-central1"
  snapshot_schedule_policy {
    schedule {
      hourly_schedule {
        hours_in_cycle = 20
        start_time     = "23:00"
      }
    }
    retention_policy {
      max_retention_days    = 10
      on_source_disk_delete = "KEEP_AUTO_SNAPSHOTS"
    }
    snapshot_properties {
      labels = {
        my_label = "value"
      }
      storage_locations = ["us"]
      guest_flush       = true
    }
  }
}
Open in Cloud Shell

Example Usage - Resource Policy Placement Policy

resource "google_compute_resource_policy" "baz" {
  name   = "gce-policy"
  region = "us-central1"
  group_placement_policy {
    vm_count = 2
    collocation = "COLLOCATED"
  }
}
Open in Cloud Shell

Example Usage - Resource Policy Placement Policy Max Distance

resource "google_compute_resource_policy" "baz" {
  name   = "gce-policy"
  region = "us-central1"
  provider = google-beta
  group_placement_policy {
    vm_count = 2
    collocation = "COLLOCATED"
    max_distance = 2
  }
}
Open in Cloud Shell

Example Usage - Resource Policy Instance Schedule Policy

resource "google_compute_resource_policy" "hourly" {
  name   = "gce-policy"
  region = "us-central1"
  description = "Start and stop instances"
  instance_schedule_policy {
    vm_start_schedule {
      schedule = "0 * * * *"
    }
    vm_stop_schedule {
      schedule = "15 * * * *"
    }
    time_zone = "US/Central"
  }
}
Open in Cloud Shell

Example Usage - Resource Policy Snapshot Schedule Chain Name

resource "google_compute_resource_policy" "hourly" {
  name   = "gce-policy"
  region = "us-central1"
  description = "chain name snapshot"
  snapshot_schedule_policy {
    schedule {
      hourly_schedule {
        hours_in_cycle = 20
        start_time     = "23:00"
      }
    }
    retention_policy {
      max_retention_days    = 14
      on_source_disk_delete = "KEEP_AUTO_SNAPSHOTS"
    }
    snapshot_properties {
      labels = {
        my_label = "value"
      }
      storage_locations = ["us"]
      guest_flush       = true
      chain_name = "test-schedule-chain-name"
    }
  }
}
Open in Cloud Shell

Example Usage - Resource Policy Consistency Group

resource "google_compute_resource_policy" "cgroup" {
  name   = "gce-policy"
  region = "europe-west1"
  disk_consistency_group_policy {
    enabled = true
  }
}

Argument Reference

The following arguments are supported:


The snapshot_schedule_policy block supports:

The schedule block supports:

The hourly_schedule block supports:

The daily_schedule block supports:

The weekly_schedule block supports:

The day_of_weeks block supports:

The retention_policy block supports:

The snapshot_properties block supports:

The group_placement_policy block supports:

The instance_schedule_policy block supports:

The vm_start_schedule block supports:

The vm_stop_schedule block supports:

The disk_consistency_group_policy block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

ResourcePolicy can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import ResourcePolicy using one of the formats above. For example:

import {
  id = "projects/{{project}}/regions/{{region}}/resourcePolicies/{{name}}"
  to = google_compute_resource_policy.default
}

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

$ terraform import google_compute_resource_policy.default projects/{{project}}/regions/{{region}}/resourcePolicies/{{name}}
$ terraform import google_compute_resource_policy.default {{project}}/{{region}}/{{name}}
$ terraform import google_compute_resource_policy.default {{region}}/{{name}}
$ terraform import google_compute_resource_policy.default {{name}}

User Project Overrides

This resource supports User Project Overrides.