Skip to content

Commit dd0fcf2

Browse files
NA2047pandirigoog
authored andcommitted
Memorystore Instance Cross Instance Replication addition (GoogleCloudPlatform#13432)
1 parent 14c007c commit dd0fcf2

File tree

3 files changed

+399
-17
lines changed

3 files changed

+399
-17
lines changed

mmv1/products/memorystore/Instance.yaml

+118
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ examples:
7474
prevent_destroy: 'true'
7575
test_vars_overrides:
7676
'prevent_destroy': 'false'
77+
- name: 'memorystore_instance_secondary_instance'
78+
primary_resource_id: 'secondary_instance'
79+
vars:
80+
primary_instance_name: 'primary-instance'
81+
primary_instance_deletion_protection_enabled: 'true'
82+
primary_instance_prevent_destroy: 'true'
83+
primary_instance_policy_name: 'my-policy-primary-instance'
84+
primary_network_name: "my-network-primary-instance"
85+
primary_instance_subnet_name: 'my-subnet-primary-instance'
86+
secondary_instance_name: 'secondary-instance'
87+
secondary_instance_deletion_protection_enabled: 'true'
88+
secondary_instance_prevent_destroy: 'true'
89+
secondary_instance_policy_name: 'my-policy-secondary-instance'
90+
secondary_network_name: "my-network-secondary-instance"
91+
secondary_instance_subnet_name: 'my-subnet-secondary-instance'
92+
test_vars_overrides:
93+
'primary_instance_deletion_protection_enabled': 'false'
94+
'secondary_instance_deletion_protection_enabled': 'false'
95+
'primary_instance_prevent_destroy': 'false'
96+
'secondary_instance_prevent_destroy': 'false'
97+
oics_vars_overrides:
98+
'primary_instance_deletion_protection_enabled': 'false'
99+
'secondary_instance_deletion_protection_enabled': 'false'
100+
'primary_instance_prevent_destroy': 'false'
101+
'secondary_instance_prevent_destroy': 'false'
77102
virtual_fields:
78103
- name: 'desired_psc_auto_connections'
79104
description: "Immutable. User inputs for the auto-created
@@ -493,6 +518,99 @@ properties:
493518
description:
494519
"Output only. Ports of the exposed endpoint."
495520
output: true
521+
- name: 'crossInstanceReplicationConfig'
522+
type: NestedObject
523+
description: Cross instance replication config
524+
default_from_api: true
525+
properties:
526+
- name: 'instanceRole'
527+
type: Enum
528+
description: |
529+
The instance role supports the following values:
530+
1. `INSTANCE_ROLE_UNSPECIFIED`: This is an independent instance that has never participated in cross instance replication. It allows both reads and writes.
531+
2. `NONE`: This is an independent instance that previously participated in cross instance replication(either as a `PRIMARY` or `SECONDARY` cluster). It allows both reads and writes.
532+
3. `PRIMARY`: This instance serves as the replication source for secondary instance that are replicating from it. Any data written to it is automatically replicated to its secondary clusters. It allows both reads and writes.
533+
4. `SECONDARY`: This instance replicates data from the primary instance. It allows only reads.
534+
enum_values:
535+
- 'INSTANCE_ROLE_UNSPECIFIED'
536+
- 'NONE'
537+
- 'PRIMARY'
538+
- 'SECONDARY'
539+
- name: 'primaryInstance'
540+
type: NestedObject
541+
description: |
542+
This field is only set for a secondary instance. Details of the primary instance that is used as the replication source for this secondary instance. This is allowed to be set only for clusters whose cluster role is of type `SECONDARY`.
543+
properties:
544+
- name: 'instance'
545+
type: String
546+
description: |
547+
The full resource path of the primary instance in the format: projects/{project}/locations/{region}/instances/{instance-id}
548+
- name: 'uid'
549+
type: String
550+
description: |
551+
The unique id of the primary instance.
552+
output: true
553+
- name: 'secondaryInstances'
554+
type: Array
555+
description: |
556+
List of secondary instances that are replicating from this primary cluster. This is allowed to be set only for instances whose cluster role is of type `PRIMARY`.
557+
item_type:
558+
type: NestedObject
559+
properties:
560+
- name: 'instance'
561+
type: String
562+
description: |
563+
The full resource path of the Nth instance in the format: projects/{project}/locations/{region}/instance/{instance-id}
564+
- name: 'uid'
565+
type: String
566+
description: |
567+
The unique id of the Nth instance.
568+
output: true
569+
- name: 'membership'
570+
type: NestedObject
571+
description: |
572+
An output only view of all the member instance participating in cross instance replication. This field is populated for all the member clusters irrespective of their cluster role.
573+
output: true
574+
properties:
575+
- name: 'primaryInstance'
576+
type: NestedObject
577+
description: |
578+
Details of the primary instance that is used as the replication source for all the secondary instances.
579+
output: true
580+
properties:
581+
- name: 'instance'
582+
type: String
583+
description: |
584+
The full resource path of the primary instance in the format: projects/{project}/locations/{region}/instance/{instance-id}
585+
output: true
586+
- name: 'uid'
587+
type: String
588+
description: |
589+
The unique id of the primary instance.
590+
output: true
591+
- name: 'secondaryInstance'
592+
type: Array
593+
description: |
594+
List of secondary instances that are replicating from the primary instance.
595+
output: true
596+
item_type:
597+
type: NestedObject
598+
properties:
599+
- name: 'instance'
600+
type: String
601+
description: |
602+
The full resource path of the secondary instance in the format: projects/{project}/locations/{region}/instance/{instance-id}
603+
output: true
604+
- name: 'uid'
605+
type: String
606+
description: |
607+
The unique id of the secondary instance.
608+
output: true
609+
- name: 'updateTime'
610+
type: String
611+
description: |
612+
The last time cross instance replication config was updated.
613+
output: true
496614
- name: 'mode'
497615
type: Enum
498616
description:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Primary instance
2+
resource "google_memorystore_instance" "primary_instance" {
3+
instance_id = "{{index $.Vars "primary_instance_name"}}"
4+
shard_count = 1
5+
desired_psc_auto_connections {
6+
network = google_compute_network.primary_producer_net.id
7+
project_id = data.google_project.project.project_id
8+
}
9+
location = "asia-east1"
10+
replica_count = 1
11+
node_type = "SHARED_CORE_NANO"
12+
transit_encryption_mode = "TRANSIT_ENCRYPTION_DISABLED"
13+
authorization_mode = "AUTH_DISABLED"
14+
engine_configs = {
15+
maxmemory-policy = "volatile-ttl"
16+
}
17+
zone_distribution_config {
18+
mode = "SINGLE_ZONE"
19+
zone = "asia-east1-c"
20+
}
21+
deletion_protection_enabled = {{index $.Vars "primary_instance_deletion_protection_enabled"}}
22+
persistence_config {
23+
mode = "RDB"
24+
rdb_config {
25+
rdb_snapshot_period = "ONE_HOUR"
26+
rdb_snapshot_start_time = "2024-10-02T15:01:23Z"
27+
}
28+
}
29+
labels = {
30+
"abc" : "xyz"
31+
}
32+
depends_on = [google_network_connectivity_service_connection_policy.primary_policy]
33+
34+
lifecycle {
35+
prevent_destroy = {{index $.Vars "primary_instance_prevent_destroy"}}
36+
}
37+
}
38+
39+
resource "google_network_connectivity_service_connection_policy" "primary_policy" {
40+
name = "{{index $.Vars "primary_instance_policy_name"}}"
41+
location = "asia-east1"
42+
service_class = "gcp-memorystore"
43+
description = "my basic service connection policy"
44+
network = google_compute_network.primary_producer_net.id
45+
psc_config {
46+
subnetworks = [google_compute_subnetwork.primary_producer_subnet.id]
47+
}
48+
}
49+
50+
resource "google_compute_subnetwork" "primary_producer_subnet" {
51+
name = "{{index $.Vars "primary_instance_subnet_name"}}"
52+
ip_cidr_range = "10.0.1.0/29"
53+
region = "asia-east1"
54+
network = google_compute_network.primary_producer_net.id
55+
}
56+
57+
resource "google_compute_network" "primary_producer_net" {
58+
name = "{{index $.Vars "primary_network_name"}}"
59+
auto_create_subnetworks = false
60+
}
61+
62+
// Secondary instance
63+
resource "google_memorystore_instance" "secondary_instance" {
64+
instance_id = "{{index $.Vars "secondary_instance_name"}}"
65+
shard_count = 1
66+
desired_psc_auto_connections {
67+
network = google_compute_network.secondary_producer_net.id
68+
project_id = data.google_project.project.project_id
69+
}
70+
location = "europe-north1"
71+
replica_count = 1
72+
node_type = "SHARED_CORE_NANO"
73+
transit_encryption_mode = "TRANSIT_ENCRYPTION_DISABLED"
74+
authorization_mode = "AUTH_DISABLED"
75+
engine_configs = {
76+
maxmemory-policy = "volatile-ttl"
77+
}
78+
zone_distribution_config {
79+
mode = "SINGLE_ZONE"
80+
zone = "europe-north1-c"
81+
}
82+
deletion_protection_enabled = {{index $.Vars "secondary_instance_deletion_protection_enabled"}}
83+
// Cross instance replication config
84+
cross_instance_replication_config {
85+
instance_role = "SECONDARY"
86+
primary_instance {
87+
instance = google_memorystore_instance.primary_instance.id
88+
}
89+
}
90+
persistence_config {
91+
mode = "RDB"
92+
rdb_config {
93+
rdb_snapshot_period = "ONE_HOUR"
94+
rdb_snapshot_start_time = "2024-10-02T15:01:23Z"
95+
}
96+
}
97+
labels = {
98+
"abc" : "xyz"
99+
}
100+
depends_on = [google_network_connectivity_service_connection_policy.secondary_policy]
101+
102+
lifecycle {
103+
prevent_destroy = {{index $.Vars "secondary_instance_prevent_destroy"}}
104+
}
105+
}
106+
107+
resource "google_network_connectivity_service_connection_policy" "secondary_policy" {
108+
name = "{{index $.Vars "secondary_instance_policy_name"}}"
109+
location = "europe-north1"
110+
service_class = "gcp-memorystore"
111+
description = "my basic service connection policy"
112+
network = google_compute_network.secondary_producer_net.id
113+
psc_config {
114+
subnetworks = [google_compute_subnetwork.secondary_producer_subnet.id]
115+
}
116+
}
117+
118+
resource "google_compute_subnetwork" "secondary_producer_subnet" {
119+
name = "{{index $.Vars "secondary_instance_subnet_name"}}"
120+
ip_cidr_range = "10.0.2.0/29"
121+
region = "europe-north1"
122+
network = google_compute_network.secondary_producer_net.id
123+
}
124+
125+
resource "google_compute_network" "secondary_producer_net" {
126+
name = "{{index $.Vars "secondary_network_name"}}"
127+
auto_create_subnetworks = false
128+
}
129+
130+
data "google_project" "project" {
131+
}

0 commit comments

Comments
 (0)