--- # ---------------------------------------------------------------------------- # # *** AUTO GENERATED CODE *** Type: MMv1 *** # # ---------------------------------------------------------------------------- # # This code is generated by Magic Modules using the following: # # Configuration: https:#github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/compute/ResourcePolicy.yaml # Template: https:#github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/resource.html.markdown.tmpl # # DO NOT EDIT this file directly. Any changes made to this file will be # overwritten during the next generation cycle. # # ---------------------------------------------------------------------------- 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)
## 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" } } } } ``` ## 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 } } } ``` ## 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" } } ``` ## 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 } } ``` ## 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" } } ``` ## 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" } } } ``` ## 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 } } ``` ## Example Usage - Resource Policy Workload Policy ```hcl resource "google_compute_resource_policy" "bar" { name = "gce-policy" region = "europe-west1" workload_policy { type = "HIGH_AVAILABILITY" } } ``` ## Example Usage - Resource Policy Workload Policy Accelerator Topology ```hcl resource "google_compute_resource_policy" "bar" { name = "gce-policy" region = "europe-west1" workload_policy { type = "HIGH_THROUGHPUT" accelerator_topology = "2x2" } } ``` ## Example Usage - Resource Policy Workload Policy Accelerator Topology Mode ```hcl resource "google_compute_resource_policy" "bar" { provider = google-beta name = "gce-policy" region = "europe-west1" workload_policy { type = "HIGH_THROUGHPUT" accelerator_topology = "2x2" accelerator_topology_mode = "AUTO_CONNECT" } } ``` ## Example Usage - Resource Policy Workload Policy Max Topology Distance ```hcl resource "google_compute_resource_policy" "bar" { name = "gce-policy" region = "europe-west1" workload_policy { type = "HIGH_THROUGHPUT" max_topology_distance = "BLOCK" } } ``` ## Example Usage - Resource Policy Placement Policy Gpu Topology ```hcl resource "google_compute_resource_policy" "baz" { name = "gce-policy" region = "europe-west9" group_placement_policy { collocation = "COLLOCATED" gpu_topology = "1x72" } } ``` ## Example Usage - Resource Policy Placement Policy Tpu Topology ```hcl resource "google_compute_resource_policy" "baz" { name = "gce-policy" region = "us-central1" provider = google-beta group_placement_policy { vm_count = 2 collocation = "COLLOCATED" tpu_topology = "4x4" } } ``` ## 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). * `workload_policy` - (Optional) Represents the workload policy. Structure is [documented below](#nested_workload_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. * `deletion_policy` - (Optional) Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. When a 'terraform destroy' or 'terraform apply' 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. The `snapshot_schedule_policy` block supports: * `schedule` - (Required) Contains one of an `hourlySchedule`, `dailySchedule`, or `weeklySchedule`. Structure is [documented below](#nested_snapshot_schedule_policy_schedule). * `retention_policy` - (Optional) Retention policy applied to snapshots created by this resource policy. Structure is [documented below](#nested_snapshot_schedule_policy_retention_policy). * `snapshot_properties` - (Optional) Properties with which the snapshots are created, such as labels. Structure is [documented below](#nested_snapshot_schedule_policy_snapshot_properties). The `schedule` block supports: * `hourly_schedule` - (Optional) The policy will execute every nth hour starting at the specified time. Structure is [documented below](#nested_snapshot_schedule_policy_schedule_hourly_schedule). * `daily_schedule` - (Optional) The policy will execute every nth day at the specified time. Structure is [documented below](#nested_snapshot_schedule_policy_schedule_daily_schedule). * `weekly_schedule` - (Optional) Allows specifying a snapshot time for each day of the week. Structure is [documented below](#nested_snapshot_schedule_policy_schedule_weekly_schedule). 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](#nested_snapshot_schedule_policy_schedule_weekly_schedule_day_of_weeks). 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](../guides/provider_versions.html.markdown)) Specifies the number of max logical switches. * `gpu_topology` - (Optional) Specifies the shape of the GPU slice, in slice based GPU families eg. A4X. * `tpu_topology` - (Optional, [Beta](../guides/provider_versions.html.markdown)) Specifies the shape of the TPU slice. The `instance_schedule_policy` block supports: * `vm_start_schedule` - (Optional) Specifies the schedule for starting instances. Structure is [documented below](#nested_instance_schedule_policy_vm_start_schedule). * `vm_stop_schedule` - (Optional) Specifies the schedule for stopping instances. Structure is [documented below](#nested_instance_schedule_policy_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. 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. The `workload_policy` block supports: * `type` - (Required) The type of workload policy. Possible values are: `HIGH_AVAILABILITY`, `HIGH_THROUGHPUT`. * `max_topology_distance` - (Optional) The maximum topology distance. This field can be set only when the workload policy type is HIGH_THROUGHPUT and cannot be set if accelerator topology or accelerator topology mode is set. Possible values are: `BLOCK`, `CLUSTER`, `SUBBLOCK`. * `accelerator_topology` - (Optional) The accelerator topology. This field can be set only when the workload policy type is HIGH_THROUGHPUT and cannot be set if max topology distance is set. * `accelerator_topology_mode` - (Optional, [Beta](../guides/provider_versions.html.markdown)) Specifies the connection mode for the accelerator topology. Supported values are: * `AUTO_CONNECT`: The interconnected chips are pre-configured at the time of VM creation. * `PROVISION_ONLY`: The interconnected chips are connected on demand. At the time of VM creation, the chips are not connected. If not specified, the default is AUTO_CONNECT. This field can be set only when the workload policy type is HIGH_THROUGHPUT and cannot be set if max topology distance is set. Possible values are: `AUTO_CONNECT`, `PROVISION_ONLY`. ## 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. - `update` - 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.12.0 and later, use an [`identity` block](https://developer.hashicorp.com/terraform/language/block/import#identity) to import ResourcePolicy using identity values. For example: ```tf import { identity = { name = "<-required value->" region = "<-optional value->" project = "<-optional value->" } to = google_compute_resource_policy.default } ``` 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).