Skip to content

Commit 5b9bda7

Browse files
himanikhmelinath
authored andcommitted
Add CMEK support for Redis cluster (GoogleCloudPlatform#12999)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 87fe4fb commit 5b9bda7

8 files changed

+111
-47
lines changed

mmv1/products/redis/Cluster.yaml

+33-12
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ examples:
126126
primary_resource_id: 'cluster-ha'
127127
vars:
128128
cluster_name: 'ha-cluster'
129-
policy_name: 'mypolicy'
130-
subnet_name: 'mysubnet'
131-
network_name: 'mynetwork'
129+
policy_name: 'my-policy'
130+
subnet_name: 'my-subnet'
131+
network_name: 'my-network'
132132
deletion_protection_enabled: 'true'
133133
test_vars_overrides:
134134
'deletion_protection_enabled': 'false'
@@ -138,9 +138,9 @@ examples:
138138
primary_resource_id: 'cluster-ha-single-zone'
139139
vars:
140140
cluster_name: 'ha-cluster-single-zone'
141-
policy_name: 'mypolicy'
142-
subnet_name: 'mysubnet'
143-
network_name: 'mynetwork'
141+
policy_name: 'my-policy'
142+
subnet_name: 'my-subnet'
143+
network_name: 'my-network'
144144
deletion_protection_enabled: 'true'
145145
test_vars_overrides:
146146
'deletion_protection_enabled': 'false'
@@ -168,9 +168,9 @@ examples:
168168
primary_resource_id: "cluster-rdb"
169169
vars:
170170
cluster_name: "rdb-cluster"
171-
policy_name: "mypolicy"
172-
subnet_name: "mysubnet"
173-
network_name: "mynetwork"
171+
policy_name: "my-policy"
172+
subnet_name: "my-subnet"
173+
network_name: "my-network"
174174
deletion_protection_enabled: 'true'
175175
test_vars_overrides:
176176
'deletion_protection_enabled': 'false'
@@ -180,14 +180,32 @@ examples:
180180
primary_resource_id: "cluster-aof"
181181
vars:
182182
cluster_name: "aof-cluster"
183-
policy_name: "mypolicy"
184-
subnet_name: "mysubnet"
185-
network_name: "mynetwork"
183+
policy_name: "my-policy"
184+
subnet_name: "my-subnet"
185+
network_name: "my-network"
186186
deletion_protection_enabled: 'true'
187187
test_vars_overrides:
188188
'deletion_protection_enabled': 'false'
189189
oics_vars_overrides:
190190
'deletion_protection_enabled': 'false'
191+
- name: "redis_cluster_cmek"
192+
primary_resource_id: "cluster-cmek"
193+
bootstrap_iam:
194+
- member: "serviceAccount:service-{project_number}@cloud-redis.iam.gserviceaccount.com"
195+
role: "roles/cloudkms.cryptoKeyEncrypterDecrypter"
196+
vars:
197+
cluster_name: "cmek-cluster"
198+
policy_name: "my-policy"
199+
subnet_name: "my-subnet"
200+
network_name: "my-network"
201+
kms_key_name: "my-key"
202+
kms_ring_name: "my-key-ring"
203+
deletion_protection_enabled: 'true'
204+
test_vars_overrides:
205+
'deletion_protection_enabled': 'false'
206+
'kms_key_name': 'acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name'
207+
oics_vars_overrides:
208+
'deletion_protection_enabled': 'false'
191209
parameters:
192210
- name: 'name'
193211
type: String
@@ -718,3 +736,6 @@ properties:
718736
- 'CONNECTION_TYPE_PRIMARY'
719737
- 'CONNECTION_TYPE_DISCOVERY'
720738
description: Type of a PSC connection targeting this service attachment.
739+
- name: 'kmsKey'
740+
type: String
741+
description: The KMS key used to encrypt the at-rest data of the cluster.

mmv1/products/redis/ClusterUserCreatedConnections.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ description: |
1818
Manages user created connections for Redis cluster
1919
docs:
2020
note: |
21+
Please ensure your connections meet the requirements outlined at
22+
https://cloud.devsite.corp.google.com/memorystore/docs/cluster/about-multiple-vpc-networking#application_connection_requirements.
2123
If you remove a connections item from the resource, the corresponding forwarding rule will no longer be functioning.
2224
If the corresponding forwarding rule is represented in your terraform configuration it is recommended to delete that
2325
`google_compute_forwarding_rule` resource at the same time.

mmv1/templates/terraform/examples/redis_cluster_aof.tf.tmpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
22
name = "{{index $.Vars "cluster_name"}}"
33
shard_count = 3
44
psc_configs {
5-
network = google_compute_network.producer_net.id
5+
network = google_compute_network.consumer_net.id
66
}
77
region = "us-central1"
88
replica_count = 0
@@ -44,20 +44,20 @@ resource "google_network_connectivity_service_connection_policy" "default" {
4444
location = "us-central1"
4545
service_class = "gcp-memorystore-redis"
4646
description = "my basic service connection policy"
47-
network = google_compute_network.producer_net.id
47+
network = google_compute_network.consumer_net.id
4848
psc_config {
49-
subnetworks = [google_compute_subnetwork.producer_subnet.id]
49+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
5050
}
5151
}
5252

53-
resource "google_compute_subnetwork" "producer_subnet" {
53+
resource "google_compute_subnetwork" "consumer_subnet" {
5454
name = "{{index $.Vars "subnet_name"}}"
5555
ip_cidr_range = "10.0.0.248/29"
5656
region = "us-central1"
57-
network = google_compute_network.producer_net.id
57+
network = google_compute_network.consumer_net.id
5858
}
5959

60-
resource "google_compute_network" "producer_net" {
60+
resource "google_compute_network" "consumer_net" {
6161
name = "{{index $.Vars "network_name"}}"
6262
auto_create_subnetworks = false
6363
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
2+
name = "{{index $.Vars "cluster_name"}}"
3+
shard_count = 3
4+
psc_configs {
5+
network = google_compute_network.consumer_net.id
6+
}
7+
kms_key = "{{index $.Vars "kms_key_name"}}"
8+
region = "us-central1"
9+
deletion_protection_enabled = {{index $.Vars "deletion_protection_enabled"}}
10+
depends_on = [
11+
google_network_connectivity_service_connection_policy.default
12+
]
13+
}
14+
15+
16+
data "google_project" "project" {
17+
}
18+
19+
resource "google_network_connectivity_service_connection_policy" "default" {
20+
name = "{{index $.Vars "policy_name"}}"
21+
location = "us-central1"
22+
service_class = "gcp-memorystore-redis"
23+
description = "my basic service connection policy"
24+
network = google_compute_network.consumer_net.id
25+
psc_config {
26+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
27+
}
28+
}
29+
30+
resource "google_compute_subnetwork" "consumer_subnet" {
31+
name = "{{index $.Vars "subnet_name"}}"
32+
ip_cidr_range = "10.0.0.248/29"
33+
region = "us-central1"
34+
network = google_compute_network.consumer_net.id
35+
}
36+
37+
resource "google_compute_network" "consumer_net" {
38+
name = "{{index $.Vars "network_name"}}"
39+
auto_create_subnetworks = false
40+
}
41+

mmv1/templates/terraform/examples/redis_cluster_ha.tf.tmpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
22
name = "{{index $.Vars "cluster_name"}}"
33
shard_count = 3
44
psc_configs {
5-
network = google_compute_network.producer_net.id
5+
network = google_compute_network.consumer_net.id
66
}
77
region = "us-central1"
88
replica_count = 1
@@ -38,20 +38,20 @@ resource "google_network_connectivity_service_connection_policy" "default" {
3838
location = "us-central1"
3939
service_class = "gcp-memorystore-redis"
4040
description = "my basic service connection policy"
41-
network = google_compute_network.producer_net.id
41+
network = google_compute_network.consumer_net.id
4242
psc_config {
43-
subnetworks = [google_compute_subnetwork.producer_subnet.id]
43+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
4444
}
4545
}
4646

47-
resource "google_compute_subnetwork" "producer_subnet" {
47+
resource "google_compute_subnetwork" "consumer_subnet" {
4848
name = "{{index $.Vars "subnet_name"}}"
4949
ip_cidr_range = "10.0.0.248/29"
5050
region = "us-central1"
51-
network = google_compute_network.producer_net.id
51+
network = google_compute_network.consumer_net.id
5252
}
5353

54-
resource "google_compute_network" "producer_net" {
54+
resource "google_compute_network" "consumer_net" {
5555
name = "{{index $.Vars "network_name"}}"
5656
auto_create_subnetworks = false
5757
}

mmv1/templates/terraform/examples/redis_cluster_ha_single_zone.tf.tmpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
22
name = "{{index $.Vars "cluster_name"}}"
33
shard_count = 3
44
psc_configs {
5-
network = google_compute_network.producer_net.id
5+
network = google_compute_network.consumer_net.id
66
}
77
region = "us-central1"
88
zone_distribution_config {
@@ -32,20 +32,20 @@ resource "google_network_connectivity_service_connection_policy" "default" {
3232
location = "us-central1"
3333
service_class = "gcp-memorystore-redis"
3434
description = "my basic service connection policy"
35-
network = google_compute_network.producer_net.id
35+
network = google_compute_network.consumer_net.id
3636
psc_config {
37-
subnetworks = [google_compute_subnetwork.producer_subnet.id]
37+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
3838
}
3939
}
4040

41-
resource "google_compute_subnetwork" "producer_subnet" {
41+
resource "google_compute_subnetwork" "consumer_subnet" {
4242
name = "{{index $.Vars "subnet_name"}}"
4343
ip_cidr_range = "10.0.0.248/29"
4444
region = "us-central1"
45-
network = google_compute_network.producer_net.id
45+
network = google_compute_network.consumer_net.id
4646
}
4747

48-
resource "google_compute_network" "producer_net" {
48+
resource "google_compute_network" "consumer_net" {
4949
name = "{{index $.Vars "network_name"}}"
5050
auto_create_subnetworks = false
5151
}

mmv1/templates/terraform/examples/redis_cluster_rdb.tf.tmpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
22
name = "{{index $.Vars "cluster_name"}}"
33
shard_count = 3
44
psc_configs {
5-
network = google_compute_network.producer_net.id
5+
network = google_compute_network.consumer_net.id
66
}
77
region = "us-central1"
88
replica_count = 0
@@ -45,20 +45,20 @@ resource "google_network_connectivity_service_connection_policy" "default" {
4545
location = "us-central1"
4646
service_class = "gcp-memorystore-redis"
4747
description = "my basic service connection policy"
48-
network = google_compute_network.producer_net.id
48+
network = google_compute_network.consumer_net.id
4949
psc_config {
50-
subnetworks = [google_compute_subnetwork.producer_subnet.id]
50+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
5151
}
5252
}
5353

54-
resource "google_compute_subnetwork" "producer_subnet" {
54+
resource "google_compute_subnetwork" "consumer_subnet" {
5555
name = "{{index $.Vars "subnet_name"}}"
5656
ip_cidr_range = "10.0.0.248/29"
5757
region = "us-central1"
58-
network = google_compute_network.producer_net.id
58+
network = google_compute_network.consumer_net.id
5959
}
6060

61-
resource "google_compute_network" "producer_net" {
61+
resource "google_compute_network" "consumer_net" {
6262
name = "{{index $.Vars "network_name"}}"
6363
auto_create_subnetworks = false
6464
}

mmv1/templates/terraform/examples/redis_cluster_secondary.tf.tmpl

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "google_redis_cluster" "primary_cluster" {
33
name = "{{index $.Vars "primary_cluster_name"}}"
44
region = "us-east1"
55
psc_configs {
6-
network = google_compute_network.producer_net.id
6+
network = google_compute_network.consumer_net.id
77
}
88

99
// Settings that should match on primary and secondary clusters.
@@ -54,7 +54,7 @@ resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
5454
name = "{{index $.Vars "secondary_cluster_name"}}"
5555
region = "europe-west1"
5656
psc_configs {
57-
network = google_compute_network.producer_net.id
57+
network = google_compute_network.consumer_net.id
5858
}
5959

6060
// Settings that should match on primary and secondary clusters.
@@ -113,17 +113,17 @@ resource "google_network_connectivity_service_connection_policy" "primary_cluste
113113
location = "us-east1"
114114
service_class = "gcp-memorystore-redis"
115115
description = "Primary cluster service connection policy"
116-
network = google_compute_network.producer_net.id
116+
network = google_compute_network.consumer_net.id
117117
psc_config {
118-
subnetworks = [google_compute_subnetwork.primary_cluster_producer_subnet.id]
118+
subnetworks = [google_compute_subnetwork.primary_cluster_consumer_subnet.id]
119119
}
120120
}
121121

122-
resource "google_compute_subnetwork" "primary_cluster_producer_subnet" {
122+
resource "google_compute_subnetwork" "primary_cluster_consumer_subnet" {
123123
name = "{{index $.Vars "primary_cluster_subnet_name"}}"
124124
ip_cidr_range = "10.0.1.0/29"
125125
region = "us-east1"
126-
network = google_compute_network.producer_net.id
126+
network = google_compute_network.consumer_net.id
127127
}
128128

129129

@@ -132,20 +132,20 @@ resource "google_network_connectivity_service_connection_policy" "secondary_clus
132132
location = "europe-west1"
133133
service_class = "gcp-memorystore-redis"
134134
description = "Secondary cluster service connection policy"
135-
network = google_compute_network.producer_net.id
135+
network = google_compute_network.consumer_net.id
136136
psc_config {
137-
subnetworks = [google_compute_subnetwork.secondary_cluster_producer_subnet.id]
137+
subnetworks = [google_compute_subnetwork.secondary_cluster_consumer_subnet.id]
138138
}
139139
}
140140

141-
resource "google_compute_subnetwork" "secondary_cluster_producer_subnet" {
141+
resource "google_compute_subnetwork" "secondary_cluster_consumer_subnet" {
142142
name = "{{index $.Vars "secondary_cluster_subnet_name"}}"
143143
ip_cidr_range = "10.0.2.0/29"
144144
region = "europe-west1"
145-
network = google_compute_network.producer_net.id
145+
network = google_compute_network.consumer_net.id
146146
}
147147

148-
resource "google_compute_network" "producer_net" {
148+
resource "google_compute_network" "consumer_net" {
149149
name = "{{index $.Vars "network_name"}}"
150150
auto_create_subnetworks = false
151151
}

0 commit comments

Comments
 (0)