Skip to content

Commit

Permalink
Added support for Persistent Disk Asynchronous Replication (part 1) (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
rosmo authored and Madhura Phadnis committed Apr 27, 2023
1 parent 7be01fc commit 683b481
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mmv1/products/compute/Disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ examples:
])"
vars:
disk_name: "test-disk"
- !ruby/object:Provider::Terraform::Examples
name: "disk_async"
primary_resource_id: "primary"
primary_resource_name: "fmt.Sprintf(\"tf-test-test-disk%s\", context[\"random_suffix\"\
])"
min_version: beta
vars:
disk_name: "async-test-disk"
secondary_disk_name: "async-secondary-test-disk"
iam_policy: !ruby/object:Api::Resource::IamPolicy
method_name_separator: '/'
fetch_iam_policy_verb: :GET
Expand Down Expand Up @@ -420,3 +429,13 @@ properties:
Indicates how many IOPS must be provisioned for the disk.
required: false
default_from_api: true
- !ruby/object:Api::Type::NestedObject
name: 'asyncPrimaryDisk'
min_version: 'beta'
properties:
- !ruby/object:Api::Type::String
name: 'disk'
description: |
Primary disk for asynchronous disk replication.
required: true
diff_suppress_func: 'compareSelfLinkRelativePaths'
19 changes: 19 additions & 0 deletions mmv1/products/compute/RegionDisk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ examples:
region_disk_name: "my-region-disk"
disk_name: "my-disk"
snapshot_name: "my-snapshot"
- !ruby/object:Provider::Terraform::Examples
name: "region_disk_async"
primary_resource_id: "primary"
primary_resource_name: "fmt.Sprintf(\"tf-test-my-region-disk%s\", context[\"random_suffix\"\
])"
min_version: beta
vars:
region_disk_name: "primary-region-disk"
secondary_region_disk_name: "secondary-region-disk"
iam_policy: !ruby/object:Api::Resource::IamPolicy
method_name_separator: '/'
fetch_iam_policy_verb: :GET
Expand Down Expand Up @@ -312,3 +321,13 @@ properties:
be used to determine whether the image was taken from the current
or a previous instance of a given disk name.
output: true
- !ruby/object:Api::Type::NestedObject
name: 'asyncPrimaryDisk'
min_version: 'beta'
properties:
- !ruby/object:Api::Type::String
name: 'disk'
description: |
Primary disk for asynchronous disk replication.
required: true
diff_suppress_func: 'compareSelfLinkRelativePaths'
28 changes: 28 additions & 0 deletions mmv1/products/compute/ResourcePolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ examples:
primary_resource_id: "hourly"
vars:
name: "gce-policy"
- !ruby/object:Provider::Terraform::Examples
name: "resource_policy_consistency_group"
min_version: "beta"
primary_resource_id: "cgroup"
vars:
name: "gce-policy"
parameters:
- !ruby/object:Api::Type::ResourceRef
name: region
Expand Down Expand Up @@ -100,6 +106,7 @@ properties:
conflicts:
- 'group_placement_policy'
- 'instance_schedule_policy'
- 'disk_consistency_group_policy'
description: |
Policy for creating snapshots of persistent disks.
properties:
Expand Down Expand Up @@ -258,6 +265,7 @@ properties:
conflicts:
- 'instance_schedule_policy'
- 'snapshot_schedule_policy'
- 'disk_consistency_group_policy'
description: |
Resource policy for instances used for placement configuration.
properties:
Expand Down Expand Up @@ -291,6 +299,7 @@ properties:
conflicts:
- 'snapshot_schedule_policy'
- 'group_placement_policy'
- 'disk_consistency_group_policy'
description: |
Resource policy for scheduling instance operations.
properties:
Expand Down Expand Up @@ -334,3 +343,22 @@ properties:
name: 'expirationTime'
description: |
The expiration time of the schedule. The timestamp is an RFC3339 string.
- !ruby/object:Api::Type::NestedObject
name: 'diskConsistencyGroupPolicy'
min_version: 'beta'
conflicts:
- 'snapshot_schedule_policy'
- 'group_placement_policy'
- 'instance_schedule_policy'
description: |
Replication consistency group for asynchronous disk replication.
send_empty_value: true
properties:
- !ruby/object:Api::Type::Boolean
name: 'enabled'
immutable: true
required: true
description: |
Enable disk consistency on the resource policy.
custom_expand: 'templates/terraform/custom_expand/disk_consistency_group_policy.erb'
custom_flatten: 'templates/terraform/custom_flatten/disk_consistency_group_policy.erb'
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%# The license inside this block applies to this file.
# Copyright 2020 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})

if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
if isEnabled, ok := original["enabled"]; ok {
if !isEnabled.(bool) {
return nil, nil
}
}
transformed := make(map[string]interface{})
return transformed, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# The license inside this block applies to this file.
# Copyright 2022 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
transformed := make(map[string]interface{})
transformed["enabled"] = true
return []interface{}{transformed}
}
23 changes: 23 additions & 0 deletions mmv1/templates/terraform/examples/disk_async.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "google_compute_disk" "primary" {
provider = google-beta

name = "<%= ctx[:vars]['disk_name'] %>"
type = "pd-ssd"
zone = "us-central1-a"

physical_block_size_bytes = 4096
}

resource "google_compute_disk" "secondary" {
provider = google-beta

name = "<%= ctx[:vars]['secondary_disk_name'] %>"
type = "pd-ssd"
zone = "us-east1-c"

async_primary_disk {
disk = google_compute_disk.primary.id
}

physical_block_size_bytes = 4096
}
26 changes: 26 additions & 0 deletions mmv1/templates/terraform/examples/region_disk_async.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_compute_region_disk" "primary" {
provider = google-beta

name = "<%= ctx[:vars]['region_disk_name'] %>"
type = "pd-ssd"
region = "us-central1"
physical_block_size_bytes = 4096

replica_zones = ["us-central1-a", "us-central1-f"]
}

resource "google_compute_region_disk" "secondary" {
provider = google-beta

name = "<%= ctx[:vars]['secondary_region_disk_name'] %>"
type = "pd-ssd"
region = "us-east1"
physical_block_size_bytes = 4096

async_primary_disk {
disk = google_compute_region_disk.primary.id
}

replica_zones = ["us-east1-b", "us-east1-c"]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "google_compute_resource_policy" "cgroup" {
provider = google-beta

name = "<%= ctx[:vars]['name'] %>"
region = "europe-west1"
disk_consistency_group_policy {
enabled = true
}
}

0 comments on commit 683b481

Please sign in to comment.