Skip to content

Commit 93705bc

Browse files
Add support for labels for Memorystore Redis clusters (#15991)
Co-authored-by: Riley Karson <[email protected]>
1 parent 9e84eab commit 93705bc

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

mmv1/products/redis/Cluster.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ sweeper:
128128
- region: "us-east1"
129129
- region: "europe-west1"
130130
examples:
131+
- name: 'redis_cluster_ha_with_labels'
132+
primary_resource_id: 'cluster-ha-with-labels'
133+
vars:
134+
cluster_name: 'ha-cluster'
135+
policy_name: 'my-policy'
136+
subnet_name: 'my-subnet'
137+
network_name: 'my-network'
138+
deletion_protection_enabled: 'true'
139+
test_vars_overrides:
140+
'deletion_protection_enabled': 'false'
141+
oics_vars_overrides:
142+
'deletion_protection_enabled': 'false'
131143
- name: 'redis_cluster_ha'
132144
primary_resource_id: 'cluster-ha'
133145
vars:
@@ -232,6 +244,9 @@ parameters:
232244
ignore_read: true
233245
default_from_api: true
234246
properties:
247+
- name: 'labels'
248+
type: KeyValueLabels
249+
description: Resource labels to represent user provided metadata.
235250
- name: 'createTime'
236251
type: Time
237252
description: |
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
resource "google_redis_cluster" "{{$.PrimaryResourceId}}" {
2+
name = "{{index $.Vars "cluster_name"}}"
3+
shard_count = 3
4+
labels = {
5+
my_key = "my_val"
6+
other_key = "other_val"
7+
}
8+
psc_configs {
9+
network = google_compute_network.consumer_net.id
10+
}
11+
region = "us-central1"
12+
replica_count = 1
13+
node_type = "REDIS_SHARED_CORE_NANO"
14+
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
15+
authorization_mode = "AUTH_MODE_DISABLED"
16+
redis_configs = {
17+
maxmemory-policy = "volatile-ttl"
18+
}
19+
deletion_protection_enabled = {{index $.Vars "deletion_protection_enabled"}}
20+
21+
zone_distribution_config {
22+
mode = "MULTI_ZONE"
23+
}
24+
maintenance_policy {
25+
weekly_maintenance_window {
26+
day = "MONDAY"
27+
start_time {
28+
hours = 1
29+
minutes = 0
30+
seconds = 0
31+
nanos = 0
32+
}
33+
}
34+
}
35+
depends_on = [
36+
google_network_connectivity_service_connection_policy.default
37+
]
38+
}
39+
40+
resource "google_network_connectivity_service_connection_policy" "default" {
41+
name = "{{index $.Vars "policy_name"}}"
42+
location = "us-central1"
43+
service_class = "gcp-memorystore-redis"
44+
description = "my basic service connection policy"
45+
network = google_compute_network.consumer_net.id
46+
psc_config {
47+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
48+
}
49+
}
50+
51+
resource "google_compute_subnetwork" "consumer_subnet" {
52+
name = "{{index $.Vars "subnet_name"}}"
53+
ip_cidr_range = "10.0.0.248/29"
54+
region = "us-central1"
55+
network = google_compute_network.consumer_net.id
56+
}
57+
58+
resource "google_compute_network" "consumer_net" {
59+
name = "{{index $.Vars "network_name"}}"
60+
auto_create_subnetworks = false
61+
}

mmv1/third_party/terraform/services/redis/resource_redis_cluster_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,3 +1418,104 @@ resource "google_redis_cluster" "cluster-ms" {
14181418
}
14191419
`, context)
14201420
}
1421+
1422+
func TestAccRedisCluster_redisClusterHaWithLabelsUpdate(t *testing.T) {
1423+
t.Parallel()
1424+
1425+
context := map[string]interface{}{
1426+
"deletion_protection_enabled": false,
1427+
"random_suffix": acctest.RandString(t, 10),
1428+
}
1429+
1430+
acctest.VcrTest(t, resource.TestCase{
1431+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1432+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1433+
CheckDestroy: testAccCheckRedisClusterDestroyProducer(t),
1434+
Steps: []resource.TestStep{
1435+
{
1436+
Config: testAccRedisCluster_redisClusterHaWithLabelsExample(context),
1437+
},
1438+
{
1439+
ResourceName: "google_redis_cluster.cluster-ha-with-labels",
1440+
ImportState: true,
1441+
ImportStateVerify: true,
1442+
ImportStateVerifyIgnore: []string{"gcs_source", "labels", "managed_backup_source", "name", "psc_configs", "region", "terraform_labels"},
1443+
},
1444+
{
1445+
Config: testAccRedisCluster_redisClusterHaWithLabelsUpdate(context),
1446+
},
1447+
{
1448+
ResourceName: "google_redis_cluster.cluster-ha-with-labels",
1449+
ImportState: true,
1450+
ImportStateVerify: true,
1451+
ImportStateVerifyIgnore: []string{"gcs_source", "labels", "managed_backup_source", "name", "psc_configs", "region", "terraform_labels"},
1452+
},
1453+
},
1454+
})
1455+
}
1456+
1457+
func testAccRedisCluster_redisClusterHaWithLabelsUpdate(context map[string]interface{}) string {
1458+
return acctest.Nprintf(`
1459+
resource "google_redis_cluster" "cluster-ha-with-labels" {
1460+
name = "tf-test-ha-cluster%{random_suffix}"
1461+
shard_count = 3
1462+
labels = {
1463+
my_key = "my_val"
1464+
other_key = "other_val"
1465+
}
1466+
psc_configs {
1467+
network = google_compute_network.consumer_net.id
1468+
}
1469+
region = "us-central1"
1470+
replica_count = 1
1471+
node_type = "REDIS_SHARED_CORE_NANO"
1472+
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
1473+
authorization_mode = "AUTH_MODE_DISABLED"
1474+
redis_configs = {
1475+
maxmemory-policy = "volatile-ttl"
1476+
}
1477+
deletion_protection_enabled = false
1478+
1479+
zone_distribution_config {
1480+
mode = "MULTI_ZONE"
1481+
}
1482+
maintenance_policy {
1483+
weekly_maintenance_window {
1484+
day = "MONDAY"
1485+
start_time {
1486+
hours = 1
1487+
minutes = 0
1488+
seconds = 0
1489+
nanos = 0
1490+
}
1491+
}
1492+
}
1493+
depends_on = [
1494+
google_network_connectivity_service_connection_policy.default
1495+
]
1496+
}
1497+
1498+
resource "google_network_connectivity_service_connection_policy" "default" {
1499+
name = "tf-test-my-policy%{random_suffix}"
1500+
location = "us-central1"
1501+
service_class = "gcp-memorystore-redis"
1502+
description = "my basic service connection policy"
1503+
network = google_compute_network.consumer_net.id
1504+
psc_config {
1505+
subnetworks = [google_compute_subnetwork.consumer_subnet.id]
1506+
}
1507+
}
1508+
1509+
resource "google_compute_subnetwork" "consumer_subnet" {
1510+
name = "tf-test-my-subnet%{random_suffix}"
1511+
ip_cidr_range = "10.0.0.248/29"
1512+
region = "us-central1"
1513+
network = google_compute_network.consumer_net.id
1514+
}
1515+
1516+
resource "google_compute_network" "consumer_net" {
1517+
name = "tf-test-my-network%{random_suffix}"
1518+
auto_create_subnetworks = false
1519+
}
1520+
`, context)
1521+
}

0 commit comments

Comments
 (0)