Skip to content

Commit

Permalink
Add resource_policy resource to compute (#1850)
Browse files Browse the repository at this point in the history
Merged PR #1850.
  • Loading branch information
Ty Larrabee authored and modular-magician committed Jun 5, 2019
1 parent 7c28bf7 commit eb9ecbc
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/terraform-beta
164 changes: 164 additions & 0 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 20 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions templates/terraform/examples/resource_policy_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
30 changes: 30 additions & 0 deletions templates/terraform/examples/resource_policy_full.tf.erb
Original file line number Diff line number Diff line change
@@ -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
}
}
}

6 changes: 6 additions & 0 deletions third_party/terraform/website-compiled/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@
<a href="/docs/providers/google/r/compute_region_instance_group_manager.html">google_compute_region_instance_group_manager</a>
</li>

<% unless version == 'ga' %>
<li<%%= sidebar_current("docs-google-compute-resource-policy") %>>
<a href="/docs/providers/google/r/compute_resource_policy.html">google_compute_resource_policy<a/>
</li>

<% end -%>
<li<%%= sidebar_current("docs-google-compute-route-x") %>>
<a href="/docs/providers/google/r/compute_route.html">google_compute_route</a>
</li>
Expand Down

0 comments on commit eb9ecbc

Please sign in to comment.