Skip to content

Commit 11163e6

Browse files
Adding nodeType field in the terraform (#10090) (#7174)
[upstream:a9d6aed791af556fb2adbd28ea509a9fd838098e] Signed-off-by: Modular Magician <[email protected]>
1 parent 18530da commit 11163e6

File tree

5 files changed

+91
-10
lines changed

5 files changed

+91
-10
lines changed

.changelog/10090.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
redis: added `node_type` and `precise_size_gb` fields to `google_redis_cluster`
3+
```

google-beta/services/redis/resource_redis_cluster.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ projects/{network_project_id_or_number}/global/networks/{network_id}.`,
9494
Description: `Optional. The authorization mode of the Redis cluster. If not provided, auth feature is disabled for the cluster. Default value: "AUTH_MODE_DISABLED" Possible values: ["AUTH_MODE_UNSPECIFIED", "AUTH_MODE_IAM_AUTH", "AUTH_MODE_DISABLED"]`,
9595
Default: "AUTH_MODE_DISABLED",
9696
},
97+
"node_type": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Optional: true,
101+
ForceNew: true,
102+
ValidateFunc: verify.ValidateEnum([]string{"REDIS_SHARED_CORE_NANO", "REDIS_HIGHMEM_MEDIUM", "REDIS_HIGHMEM_XLARGE", "REDIS_STANDARD_SMALL", ""}),
103+
Description: `The nodeType for the Redis cluster.
104+
If not provided, REDIS_HIGHMEM_MEDIUM will be used as default Possible values: ["REDIS_SHARED_CORE_NANO", "REDIS_HIGHMEM_MEDIUM", "REDIS_HIGHMEM_XLARGE", "REDIS_STANDARD_SMALL"]`,
105+
},
97106
"region": {
98107
Type: schema.TypeString,
99108
Computed: true,
@@ -161,6 +170,11 @@ projects/{network_project_id}/global/networks/{network_id}.`,
161170
},
162171
},
163172
},
173+
"precise_size_gb": {
174+
Type: schema.TypeFloat,
175+
Computed: true,
176+
Description: `Output only. Redis memory precise size in GB for the entire cluster.`,
177+
},
164178
"psc_connections": {
165179
Type: schema.TypeList,
166180
Computed: true,
@@ -270,6 +284,12 @@ func resourceRedisClusterCreate(d *schema.ResourceData, meta interface{}) error
270284
} else if v, ok := d.GetOkExists("transit_encryption_mode"); !tpgresource.IsEmptyValue(reflect.ValueOf(transitEncryptionModeProp)) && (ok || !reflect.DeepEqual(v, transitEncryptionModeProp)) {
271285
obj["transitEncryptionMode"] = transitEncryptionModeProp
272286
}
287+
nodeTypeProp, err := expandRedisClusterNodeType(d.Get("node_type"), d, config)
288+
if err != nil {
289+
return err
290+
} else if v, ok := d.GetOkExists("node_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(nodeTypeProp)) && (ok || !reflect.DeepEqual(v, nodeTypeProp)) {
291+
obj["nodeType"] = nodeTypeProp
292+
}
273293
pscConfigsProp, err := expandRedisClusterPscConfigs(d.Get("psc_configs"), d, config)
274294
if err != nil {
275295
return err
@@ -406,6 +426,9 @@ func resourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error {
406426
if err := d.Set("transit_encryption_mode", flattenRedisClusterTransitEncryptionMode(res["transitEncryptionMode"], d, config)); err != nil {
407427
return fmt.Errorf("Error reading Cluster: %s", err)
408428
}
429+
if err := d.Set("node_type", flattenRedisClusterNodeType(res["nodeType"], d, config)); err != nil {
430+
return fmt.Errorf("Error reading Cluster: %s", err)
431+
}
409432
if err := d.Set("discovery_endpoints", flattenRedisClusterDiscoveryEndpoints(res["discoveryEndpoints"], d, config)); err != nil {
410433
return fmt.Errorf("Error reading Cluster: %s", err)
411434
}
@@ -421,6 +444,9 @@ func resourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error {
421444
if err := d.Set("size_gb", flattenRedisClusterSizeGb(res["sizeGb"], d, config)); err != nil {
422445
return fmt.Errorf("Error reading Cluster: %s", err)
423446
}
447+
if err := d.Set("precise_size_gb", flattenRedisClusterPreciseSizeGb(res["preciseSizeGb"], d, config)); err != nil {
448+
return fmt.Errorf("Error reading Cluster: %s", err)
449+
}
424450
if err := d.Set("shard_count", flattenRedisClusterShardCount(res["shardCount"], d, config)); err != nil {
425451
return fmt.Errorf("Error reading Cluster: %s", err)
426452
}
@@ -618,6 +644,10 @@ func flattenRedisClusterTransitEncryptionMode(v interface{}, d *schema.ResourceD
618644
return v
619645
}
620646

647+
func flattenRedisClusterNodeType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
648+
return v
649+
}
650+
621651
func flattenRedisClusterDiscoveryEndpoints(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
622652
if v == nil {
623653
return v
@@ -814,6 +844,10 @@ func flattenRedisClusterSizeGb(v interface{}, d *schema.ResourceData, config *tr
814844
return v // let terraform core handle it otherwise
815845
}
816846

847+
func flattenRedisClusterPreciseSizeGb(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
848+
return v
849+
}
850+
817851
func flattenRedisClusterShardCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
818852
// Handles the string fixed64 format
819853
if strVal, ok := v.(string); ok {
@@ -839,6 +873,10 @@ func expandRedisClusterTransitEncryptionMode(v interface{}, d tpgresource.Terraf
839873
return v, nil
840874
}
841875

876+
func expandRedisClusterNodeType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
877+
return v, nil
878+
}
879+
842880
func expandRedisClusterPscConfigs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
843881
l := v.([]interface{})
844882
req := make([]interface{}, 0, len(l))

google-beta/services/redis/resource_redis_cluster_generated_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ resource "google_redis_cluster" "cluster-ha" {
6666
}
6767
region = "us-central1"
6868
replica_count = 1
69+
node_type = "REDIS_SHARED_CORE_NANO"
6970
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
7071
authorization_mode = "AUTH_MODE_DISABLED"
7172
depends_on = [

google-beta/services/redis/resource_redis_cluster_test.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@ import (
1010
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
1111
)
1212

13+
func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
14+
t.Parallel()
15+
16+
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
17+
18+
acctest.VcrTest(t, resource.TestCase{
19+
PreCheck: func() { acctest.AccTestPreCheck(t) },
20+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
21+
CheckDestroy: testAccCheckRedisClusterDestroyProducer(t),
22+
Steps: []resource.TestStep{
23+
{
24+
// create cluster with replica count 1
25+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true /*nodeType = */, "REDIS_STANDARD_SMALL"),
26+
},
27+
{
28+
ResourceName: "google_redis_cluster.test",
29+
ImportState: true,
30+
ImportStateVerify: true,
31+
ImportStateVerifyIgnore: []string{"psc_configs"},
32+
},
33+
{
34+
// clean up the resource
35+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false /*nodeType = */, "REDIS_STANDARD_SMALL"),
36+
},
37+
},
38+
})
39+
}
40+
1341
// Validate that replica count is updated for the cluster
1442
func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
1543
t.Parallel()
@@ -23,7 +51,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
2351
Steps: []resource.TestStep{
2452
{
2553
// create cluster with replica count 1
26-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true),
54+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true /* nodeType = */, ""),
2755
},
2856
{
2957
ResourceName: "google_redis_cluster.test",
@@ -33,7 +61,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
3361
},
3462
{
3563
// update replica count to 2
36-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 2 /* shardCount = */, 3, true),
64+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 2 /* shardCount = */, 3, true /*nodeType = */, ""),
3765
},
3866
{
3967
ResourceName: "google_redis_cluster.test",
@@ -43,11 +71,11 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
4371
},
4472
{
4573
// clean up the resource
46-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 2 /* shardCount = */, 3, false),
74+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 2 /* shardCount = */, 3, false /*nodeType = */, ""),
4775
},
4876
{
4977
// update replica count to 0
50-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, true),
78+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, true /*nodeType = */, ""),
5179
},
5280
{
5381
ResourceName: "google_redis_cluster.test",
@@ -57,7 +85,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) {
5785
},
5886
{
5987
// clean up the resource
60-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false),
88+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false /*nodeType = */, ""),
6189
},
6290
},
6391
})
@@ -76,7 +104,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
76104
Steps: []resource.TestStep{
77105
{
78106
// create cluster with shard count 3
79-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true),
107+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true /*nodeType = */, ""),
80108
},
81109
{
82110
ResourceName: "google_redis_cluster.test",
@@ -86,7 +114,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
86114
},
87115
{
88116
// update shard count to 5
89-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, true),
117+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, true /*nodeType = */, ""),
90118
},
91119
{
92120
ResourceName: "google_redis_cluster.test",
@@ -96,13 +124,13 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) {
96124
},
97125
{
98126
// clean up the resource
99-
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, false),
127+
Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, false /* nodeType = */, ""),
100128
},
101129
},
102130
})
103131
}
104132

105-
func createOrUpdateRedisCluster(name string, replicaCount int, shardCount int, preventDestroy bool) string {
133+
func createOrUpdateRedisCluster(name string, replicaCount int, shardCount int, preventDestroy bool, nodeType string) string {
106134
lifecycleBlock := ""
107135
if preventDestroy {
108136
lifecycleBlock = `
@@ -116,6 +144,7 @@ resource "google_redis_cluster" "test" {
116144
name = "%s"
117145
replica_count = %d
118146
shard_count = %d
147+
node_type = "%s"
119148
region = "us-central1"
120149
psc_configs {
121150
network = google_compute_network.producer_net.id
@@ -151,5 +180,5 @@ resource "google_compute_network" "producer_net" {
151180
name = "%s"
152181
auto_create_subnetworks = false
153182
}
154-
`, name, replicaCount, shardCount, lifecycleBlock, name, name, name)
183+
`, name, replicaCount, shardCount, nodeType, lifecycleBlock, name, name, name)
155184
}

website/docs/r/redis_cluster.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ resource "google_redis_cluster" "cluster-ha" {
4545
}
4646
region = "us-central1"
4747
replica_count = 1
48+
node_type = "REDIS_SHARED_CORE_NANO"
4849
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
4950
authorization_mode = "AUTH_MODE_DISABLED"
5051
depends_on = [
@@ -126,6 +127,12 @@ The following arguments are supported:
126127
Default value is `TRANSIT_ENCRYPTION_MODE_DISABLED`.
127128
Possible values are: `TRANSIT_ENCRYPTION_MODE_UNSPECIFIED`, `TRANSIT_ENCRYPTION_MODE_DISABLED`, `TRANSIT_ENCRYPTION_MODE_SERVER_AUTHENTICATION`.
128129

130+
* `node_type` -
131+
(Optional)
132+
The nodeType for the Redis cluster.
133+
If not provided, REDIS_HIGHMEM_MEDIUM will be used as default
134+
Possible values are: `REDIS_SHARED_CORE_NANO`, `REDIS_HIGHMEM_MEDIUM`, `REDIS_HIGHMEM_XLARGE`, `REDIS_STANDARD_SMALL`.
135+
129136
* `replica_count` -
130137
(Optional)
131138
Optional. The number of replica nodes per shard.
@@ -172,6 +179,9 @@ In addition to the arguments listed above, the following computed attributes are
172179
* `size_gb` -
173180
Output only. Redis memory size in GB for the entire cluster.
174181

182+
* `precise_size_gb` -
183+
Output only. Redis memory precise size in GB for the entire cluster.
184+
175185

176186
<a name="nested_discovery_endpoints"></a>The `discovery_endpoints` block contains:
177187

0 commit comments

Comments
 (0)