From eb9ecbc3032efc1d1fb5e46d090db0eb24d3c8c7 Mon Sep 17 00:00:00 2001 From: Ty Larrabee Date: Wed, 5 Jun 2019 09:51:05 -0700 Subject: [PATCH] Add resource_policy resource to compute (#1850) Merged PR #1850. --- build/terraform-beta | 2 +- products/compute/api.yaml | 164 ++++++++++++++++++ products/compute/terraform.yaml | 20 +++ .../examples/resource_policy_basic.tf.erb | 18 ++ .../examples/resource_policy_full.tf.erb | 30 ++++ .../terraform/website-compiled/google.erb | 6 + 6 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 templates/terraform/examples/resource_policy_basic.tf.erb create mode 100644 templates/terraform/examples/resource_policy_full.tf.erb diff --git a/build/terraform-beta b/build/terraform-beta index d0131a1bdb64..95a4a713141e 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit d0131a1bdb6414c5516c5c2a7e76fc195edc3cfd +Subproject commit 95a4a713141e83a7b120c57beb49012e9dd8ebf9 diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 97ea66da58bd..e629832cbe4d 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -5840,6 +5840,170 @@ objects: description: | URL of the disk type resource describing which disk type to use to create the disk. Provide this when creating the disk. + - !ruby/object:Api::Resource + name: 'ResourcePolicy' + min_version: beta + kind: 'compute#resourcePolicy' + base_url: projects/{{project}}/regions/{{region}}/resourcePolicies + input: true + has_self_link: true + description: | + A policy that can be attached to a resource to specify or schedule actions on that resource. + async: !ruby/object:Api::Async + operation: !ruby/object:Api::Async::Operation + kind: 'compute#operation' + path: 'name' + base_url: 'projects/{{project}}/global/operations/{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::Async::Result + path: 'targetLink' + status: !ruby/object:Api::Async::Status + path: 'status' + complete: 'DONE' + allowed: + - 'PENDING' + - 'RUNNING' + - 'DONE' + error: !ruby/object:Api::Async::Error + path: 'error/errors' + message: 'message' + parameters: + - !ruby/object:Api::Type::ResourceRef + name: region + resource: Region + imports: name + description: Region where resource policy resides. + input: true + required: true + properties: + - !ruby/object:Api::Type::String + name: 'name' + required: true + description: | + 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. + - !ruby/object:Api::Type::NestedObject + name: 'snapshotSchedulePolicy' + description: | + Policy for creating snapshots of persistent disks. + properties: + - !ruby/object:Api::Type::NestedObject + name: 'schedule' + description: | + Contains one of an `hourlySchedule`, `dailySchedule`, or `weeklySchedule`. + required: true + properties: + - !ruby/object:Api::Type::NestedObject + name: 'hourlySchedule' + description: | + The policy will execute every nth hour starting at the specified time. + properties: + - !ruby/object:Api::Type::Integer + name: 'hoursInCycle' + description: | + The number of hours between snapshots. + required: true + - !ruby/object:Api::Type::String + name: 'startTime' + description: | + Time within the window to start the operations. + It must be in format "HH:MM", + where HH : [00-23] and MM : [00-00] GMT. + required: true + - !ruby/object:Api::Type::NestedObject + name: 'dailySchedule' + description: | + The policy will execute every nth day at the specified time. + properties: + - !ruby/object:Api::Type::Integer + name: 'daysInCycle' + description: | + The number of days between snapshots. + required: true + - !ruby/object:Api::Type::String + name: 'startTime' + description: | + 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. + required: true + - !ruby/object:Api::Type::NestedObject + name: 'weeklySchedule' + description: | + Allows specifying a snapshot time for each day of the week. + properties: + - !ruby/object:Api::Type::Array + name: 'dayOfWeeks' + description: | + May contain up to seven (one for each day of the week) snapshot times. + required: true + min_size: 1 + max_size: 7 + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: 'startTime' + description: | + Time within the window to start the operations. + It must be in format "HH:MM", where HH : [00-23] and MM : [00-00] GMT. + required: true + - !ruby/object:Api::Type::Enum + name: 'day' + description: | + The day of the week to create the snapshot. e.g. MONDAY + required: true + values: + - :MONDAY + - :TUESDAY + - :WEDNESDAY + - :THURSDAY + - :FRIDAY + - :SATURDAY + - :SUNDAY + - !ruby/object:Api::Type::NestedObject + name: 'retentionPolicy' + description: | + Retention policy applied to snapshots created by this resource policy. + properties: + - !ruby/object:Api::Type::Integer + name: 'maxRetentionDays' + description: | + Maximum age of the snapshot that is allowed to be kept. + required: true + - !ruby/object:Api::Type::Enum + name: 'onSourceDiskDelete' + description: | + Specifies the behavior to apply to scheduled snapshots when + the source disk is deleted. + Valid options are KEEP_AUTO_SNAPSHOTS and APPLY_RETENTION_POLICY + default_value: :KEEP_AUTO_SNAPSHOTS + values: + - :KEEP_AUTO_SNAPSHOTS + - :APPLY_RETENTION_POLICY + - !ruby/object:Api::Type::NestedObject + name: 'snapshotProperties' + description: | + Properties with which the snapshots are created, such as labels. + properties: + - !ruby/object:Api::Type::KeyValuePairs + name: 'labels' + description: | + A set of key-value pairs. + - !ruby/object:Api::Type::Array + name: 'storageLocations' + max_size: 1 + description: | + GCS bucket location in which to store the snapshot (regional or multi-regional). + item_type: Api::Type::String + - !ruby/object:Api::Type::Boolean + name: 'guestFlush' + description: | + Whether to perform a 'guest aware' snapshot. - !ruby/object:Api::Resource name: 'Route' kind: 'compute#route' diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 37c4fff9e7d7..695b480fa77b 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -942,6 +942,26 @@ overrides: !ruby/object:Overrides::ResourceOverrides snapshot_name: "my-snapshot" RegionDiskType: !ruby/object:Overrides::Terraform::ResourceOverride exclude: true + ResourcePolicy: !ruby/object:Overrides::Terraform::ResourceOverride + examples: + - !ruby/object:Provider::Terraform::Examples + name: "resource_policy_basic" + primary_resource_id: "foo" + vars: + name: "policy" + - !ruby/object:Provider::Terraform::Examples + name: "resource_policy_full" + primary_resource_id: "bar" + vars: + name: "policy" + properties: + region: !ruby/object:Overrides::Terraform::PropertyOverride + required: false + default_from_api: true + snapshotSchedulePolicy.schedule.weeklySchedule.dayOfWeeks: !ruby/object:Overrides::Terraform::PropertyOverride + is_set: true + snapshotSchedulePolicy.snapshotProperties.storageLocations: !ruby/object:Overrides::Terraform::PropertyOverride + is_set: true Route: !ruby/object:Overrides::Terraform::ResourceOverride examples: - !ruby/object:Provider::Terraform::Examples diff --git a/templates/terraform/examples/resource_policy_basic.tf.erb b/templates/terraform/examples/resource_policy_basic.tf.erb new file mode 100644 index 000000000000..ff18bc672f42 --- /dev/null +++ b/templates/terraform/examples/resource_policy_basic.tf.erb @@ -0,0 +1,18 @@ +provider "google-beta" { + region = "us-central1" + zone = "us-central1-a" +} + +resource "google_compute_resource_policy" "foo" { + provider = "google-beta" + name = "<%= ctx[:vars]['name'] %>" + region = "us-central1" + snapshot_schedule_policy { + schedule { + daily_schedule { + days_in_cycle = 1 + start_time = "04:00" + } + } + } +} diff --git a/templates/terraform/examples/resource_policy_full.tf.erb b/templates/terraform/examples/resource_policy_full.tf.erb new file mode 100644 index 000000000000..1bf9b44000b7 --- /dev/null +++ b/templates/terraform/examples/resource_policy_full.tf.erb @@ -0,0 +1,30 @@ +provider "google-beta" { + region = "us-central1" + zone = "us-central1-a" +} + +resource "google_compute_resource_policy" "bar" { + provider = "google-beta" + name = "<%= ctx[:vars]['name'] %>" + 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 + } + } +} + diff --git a/third_party/terraform/website-compiled/google.erb b/third_party/terraform/website-compiled/google.erb index 33ff7a08f003..8d79148bfaef 100644 --- a/third_party/terraform/website-compiled/google.erb +++ b/third_party/terraform/website-compiled/google.erb @@ -540,6 +540,12 @@ google_compute_region_instance_group_manager +<% unless version == 'ga' %> + > + google_compute_resource_policy + + +<% end -%> > google_compute_route