A policy that can be attached to a resource to specify or schedule actions on that resource.
To get more information about ResourcePolicy, see:
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"
}
}
}
}
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
}
}
}
resource "google_compute_resource_policy" "baz" {
name = "gce-policy"
region = "us-central1"
group_placement_policy {
vm_count = 2
collocation = "COLLOCATED"
}
}
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
}
}
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"
}
}
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"
}
}
}
resource "google_compute_resource_policy" "cgroup" {
name = "gce-policy"
region = "europe-west1"
disk_consistency_group_policy {
enabled = true
}
}
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.description
-
(Optional)
An optional description of this resource. Provide this property when you create the resource.
snapshot_schedule_policy
-
(Optional)
Policy for creating snapshots of persistent disks.
Structure is documented below.
group_placement_policy
-
(Optional)
Resource policy for instances used for placement configuration.
Structure is documented below.
instance_schedule_policy
-
(Optional)
Resource policy for scheduling instance operations.
Structure is documented below.
disk_consistency_group_policy
-
(Optional)
Replication consistency group for asynchronous disk replication.
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.
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 an hourly format "HH:MM",
where HH : [00-23] and MM : [00] GMT.
eg: 21:00
The daily_schedule
block supports:
days_in_cycle
-
(Required)
Defines a schedule with units measured in days. The value determines how many days pass between the start of each cycle. Days in cycle for snapshot schedule policy must be 1.
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
Possible values are: MONDAY
, TUESDAY
, WEDNESDAY
, THURSDAY
, FRIDAY
, SATURDAY
, SUNDAY
.
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.
Default value is KEEP_AUTO_SNAPSHOTS
.
Possible values are: KEEP_AUTO_SNAPSHOTS
, APPLY_RETENTION_POLICY
.
The snapshot_properties
block supports:
labels
-
(Optional)
A set of key-value pairs.
storage_locations
-
(Optional)
Cloud Storage bucket location to store the auto snapshot
(regional or multi-regional)
guest_flush
-
(Optional)
Whether to perform a 'guest aware' snapshot.
chain_name
-
(Optional)
Creates the new snapshot in the snapshot chain labeled with the
specified name. The chain name must be 1-63 characters long and comply
with RFC1035.
The group_placement_policy
block supports:
vm_count
-
(Optional)
Number of VMs in this placement group. Google does not recommend that you use this field
unless you use a compact policy and you want your policy to work only if it contains this
exact number of VMs.
availability_domain_count
-
(Optional)
The number of availability domains instances will be spread across. If two instances are in different
availability domain, they will not be put in the same low latency network
collocation
-
(Optional)
Collocation specifies whether to place VMs inside the same availability domain on the same low-latency network.
Specify COLLOCATED
to enable collocation. Can only be specified with vm_count
. If compute instances are created
with a COLLOCATED policy, then exactly vm_count
instances must be created at the same time with the resource policy
attached.
Possible values are: COLLOCATED
.
max_distance
-
(Optional, Beta)
Specifies the number of max logical switches.
The instance_schedule_policy
block supports:
vm_start_schedule
-
(Optional)
Specifies the schedule for starting instances.
Structure is documented below.
vm_stop_schedule
-
(Optional)
Specifies the schedule for stopping instances.
Structure is documented below.
time_zone
-
(Required)
Specifies the time zone to be used in interpreting the schedule. The value of this field must be a time zone name
from the tz database: http://en.wikipedia.org/wiki/Tz_database.
start_time
-
(Optional)
The start time of the schedule. The timestamp is an RFC3339 string.
expiration_time
-
(Optional)
The expiration time of the schedule. The timestamp is an RFC3339 string.
The vm_start_schedule
block supports:
schedule
-
(Required)
Specifies the frequency for the operation, using the unix-cron format.The vm_stop_schedule
block supports:
schedule
-
(Required)
Specifies the frequency for the operation, using the unix-cron format.The disk_consistency_group_policy
block supports:
enabled
-
(Required)
Enable disk consistency on the resource policy.In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with format projects/{{project}}/regions/{{region}}/resourcePolicies/{{name}}
self_link
- The URI of the created resource.This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.delete
- Default is 20 minutes.ResourcePolicy can be imported using any of these accepted formats:
projects/{{project}}/regions/{{region}}/resourcePolicies/{{name}}
{{project}}/{{region}}/{{name}}
{{region}}/{{name}}
{{name}}
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}}
This resource supports User Project Overrides.