» google_compute_resource_policy

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

» Example Usage - Resource Policy Basic

provider "google-beta" {
  region = "us-central1"
  zone   = "us-central1-a"
}

resource "google_compute_resource_policy" "foo" {
  provider = "google-beta"
  name = "policy"
  region = "us-central1"
  snapshot_schedule_policy {
    schedule {
      daily_schedule {
        days_in_cycle = 1
        start_time = "04:00"
      }
    }
  }
}

» Example Usage - Resource Policy Full

provider "google-beta" {
  region = "us-central1"
  zone   = "us-central1-a"
}

resource "google_compute_resource_policy" "bar" {
  provider = "google-beta"
  name = "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
    }
  }
}

» Argument Reference

The following arguments are supported:

  • name - (Required) The name of the resource, provided by the client when initially creating the resource. The resource name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • snapshot_schedule_policy - (Optional) Policy for creating snapshots of persistent disks. Structure is documented below.

  • region - (Optional) Region where resource policy resides.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The snapshot_schedule_policy block supports:

  • schedule - (Required) Contains one of an hourlySchedule, dailySchedule, or weeklySchedule. Structure is documented below.

  • retention_policy - (Optional) Retention policy applied to snapshots created by this resource policy. Structure is documented below.

  • snapshot_properties - (Optional) Properties with which the snapshots are created, such as labels. Structure is documented below.

The schedule block supports:

  • hourly_schedule - (Optional) The policy will execute every nth hour starting at the specified time. Structure is documented below.

  • daily_schedule - (Optional) The policy will execute every nth day at the specified time. Structure is documented below.

  • weekly_schedule - (Optional) Allows specifying a snapshot time for each day of the week. Structure is documented below.

The hourly_schedule block supports:

  • hours_in_cycle - (Required) The number of hours between snapshots.

  • start_time - (Required) Time within the window to start the operations. It must be in format "HH:MM", where HH : [00-23] and MM : [00-00] GMT.

The daily_schedule block supports:

  • days_in_cycle - (Required) The number of days between snapshots.

  • start_time - (Required) This must be in UTC format that resolves to one of 00:00, 04:00, 08:00, 12:00, 16:00, or 20:00. For example, both 13:00-5 and 08:00 are valid.

The weekly_schedule block supports:

  • day_of_weeks - (Required) May contain up to seven (one for each day of the week) snapshot times. Structure is documented below.

The day_of_weeks block supports:

  • start_time - (Required) Time within the window to start the operations. It must be in format "HH:MM", where HH : [00-23] and MM : [00-00] GMT.

  • day - (Required) The day of the week to create the snapshot. e.g. MONDAY

The retention_policy block supports:

  • max_retention_days - (Required) Maximum age of the snapshot that is allowed to be kept.

  • on_source_disk_delete - (Optional) Specifies the behavior to apply to scheduled snapshots when the source disk is deleted. Valid options are KEEP_AUTO_SNAPSHOTS and APPLY_RETENTION_POLICY

The snapshot_properties block supports:

  • labels - (Optional) A set of key-value pairs.

  • storage_locations - (Optional) GCS bucket location in which to store the snapshot (regional or multi-regional).

  • guest_flush - (Optional) Whether to perform a 'guest aware' snapshot.

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 4 minutes.
  • delete - Default is 4 minutes.

» Import

ResourcePolicy can be imported using any of these accepted formats:

$ terraform import -provider=google-beta google_compute_resource_policy.default projects/{{project}}/regions/{{region}}/resourcePolicies/{{name}}
$ terraform import -provider=google-beta google_compute_resource_policy.default {{project}}/{{region}}/{{name}}
$ terraform import -provider=google-beta google_compute_resource_policy.default {{region}}/{{name}}
$ terraform import -provider=google-beta google_compute_resource_policy.default {{name}}

» User Project Overrides

This resource supports User Project Overrides.