| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** AUTO GENERATED CODE *** Type: MMv1 *** |
| # |
| # ---------------------------------------------------------------------------- |
| # |
| # This file is automatically generated by Magic Modules and manual |
| # changes will be clobbered when the file is regenerated. |
| # |
| # Please read more about how to change this file in |
| # .github/CONTRIBUTING.md. |
| # |
| # ---------------------------------------------------------------------------- |
| subcategory: "Compute Engine" |
| description: |- |
| A policy that can be attached to a resource to specify or schedule actions on that resource. |
| --- |
| |
| # 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: |
| |
| * [API documentation](https://cloud.google.com/compute/docs/reference/rest/v1/resourcePolicies) |
| |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Basic |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_full&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Full |
| |
| |
| ```hcl |
| 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 |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_placement_policy&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Placement Policy |
| |
| |
| ```hcl |
| resource "google_compute_resource_policy" "baz" { |
| name = "gce-policy" |
| region = "us-central1" |
| group_placement_policy { |
| vm_count = 2 |
| collocation = "COLLOCATED" |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_placement_policy_max_distance&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Placement Policy Max Distance |
| |
| |
| ```hcl |
| 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 |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_instance_schedule_policy&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Instance Schedule Policy |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_snapshot_schedule_chain_name&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Snapshot Schedule Chain Name |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=resource_policy_consistency_group&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Resource Policy Consistency Group |
| |
| |
| ```hcl |
| 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: |
| |
| |
| * `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](#nested_snapshot_schedule_policy). |
| |
| * `group_placement_policy` - |
| (Optional) |
| Resource policy for instances used for placement configuration. |
| Structure is [documented below](#nested_group_placement_policy). |
| |
| * `instance_schedule_policy` - |
| (Optional) |
| Resource policy for scheduling instance operations. |
| Structure is [documented below](#nested_instance_schedule_policy). |
| |
| * `disk_consistency_group_policy` - |
| (Optional) |
| Replication consistency group for asynchronous disk replication. |
| Structure is [documented below](#nested_disk_consistency_group_policy). |
| |
| * `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. |
| |
| |
| <a name="nested_snapshot_schedule_policy"></a>The `snapshot_schedule_policy` block supports: |
| |
| * `schedule` - |
| (Required) |
| Contains one of an `hourlySchedule`, `dailySchedule`, or `weeklySchedule`. |
| Structure is [documented below](#nested_schedule). |
| |
| * `retention_policy` - |
| (Optional) |
| Retention policy applied to snapshots created by this resource policy. |
| Structure is [documented below](#nested_retention_policy). |
| |
| * `snapshot_properties` - |
| (Optional) |
| Properties with which the snapshots are created, such as labels. |
| Structure is [documented below](#nested_snapshot_properties). |
| |
| |
| <a name="nested_schedule"></a>The `schedule` block supports: |
| |
| * `hourly_schedule` - |
| (Optional) |
| The policy will execute every nth hour starting at the specified time. |
| Structure is [documented below](#nested_hourly_schedule). |
| |
| * `daily_schedule` - |
| (Optional) |
| The policy will execute every nth day at the specified time. |
| Structure is [documented below](#nested_daily_schedule). |
| |
| * `weekly_schedule` - |
| (Optional) |
| Allows specifying a snapshot time for each day of the week. |
| Structure is [documented below](#nested_weekly_schedule). |
| |
| |
| <a name="nested_hourly_schedule"></a>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 |
| |
| <a name="nested_daily_schedule"></a>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. |
| |
| <a name="nested_weekly_schedule"></a>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](#nested_day_of_weeks). |
| |
| |
| <a name="nested_day_of_weeks"></a>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`. |
| |
| <a name="nested_retention_policy"></a>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`. |
| |
| <a name="nested_snapshot_properties"></a>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. |
| |
| <a name="nested_group_placement_policy"></a>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](https://terraform.io/docs/providers/google/guides/provider_versions.html)) |
| Specifies the number of max logical switches. |
| |
| <a name="nested_instance_schedule_policy"></a>The `instance_schedule_policy` block supports: |
| |
| * `vm_start_schedule` - |
| (Optional) |
| Specifies the schedule for starting instances. |
| Structure is [documented below](#nested_vm_start_schedule). |
| |
| * `vm_stop_schedule` - |
| (Optional) |
| Specifies the schedule for stopping instances. |
| Structure is [documented below](#nested_vm_stop_schedule). |
| |
| * `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. |
| |
| |
| <a name="nested_vm_start_schedule"></a>The `vm_start_schedule` block supports: |
| |
| * `schedule` - |
| (Required) |
| Specifies the frequency for the operation, using the unix-cron format. |
| |
| <a name="nested_vm_stop_schedule"></a>The `vm_stop_schedule` block supports: |
| |
| * `schedule` - |
| (Required) |
| Specifies the frequency for the operation, using the unix-cron format. |
| |
| <a name="nested_disk_consistency_group_policy"></a>The `disk_consistency_group_policy` block supports: |
| |
| * `enabled` - |
| (Required) |
| Enable disk consistency on the resource policy. |
| |
| ## Attributes Reference |
| |
| 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. |
| |
| |
| ## Timeouts |
| |
| This resource provides the following |
| [Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: |
| |
| - `create` - Default is 20 minutes. |
| - `delete` - Default is 20 minutes. |
| |
| ## Import |
| |
| |
| 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](https://developer.hashicorp.com/terraform/language/import) to import ResourcePolicy using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "projects/{{project}}/regions/{{region}}/resourcePolicies/{{name}}" |
| to = google_compute_resource_policy.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |