From a7b917e677eaf441c43e1e5dd35e32f85b06e099 Mon Sep 17 00:00:00 2001 From: shailymittal-github <159908679+shailymittal-github@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:39:52 +0530 Subject: [PATCH] Adding nodeType field in the terraform (#10090) --- mmv1/products/redis/Cluster.yaml | 18 +++++++ .../examples/redis_cluster_ha.tf.erb | 1 + .../redis/resource_redis_cluster_test.go.erb | 49 +++++++++++++++---- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/mmv1/products/redis/Cluster.yaml b/mmv1/products/redis/Cluster.yaml index 08751531ba2f..d815eb7b9a0a 100644 --- a/mmv1/products/redis/Cluster.yaml +++ b/mmv1/products/redis/Cluster.yaml @@ -110,6 +110,19 @@ properties: default_value: :TRANSIT_ENCRYPTION_MODE_DISABLED immutable: true required: false + - !ruby/object:Api::Type::Enum + name: nodeType + description: | + The nodeType for the Redis cluster. + If not provided, REDIS_HIGHMEM_MEDIUM will be used as default + values: + - :REDIS_SHARED_CORE_NANO + - :REDIS_HIGHMEM_MEDIUM + - :REDIS_HIGHMEM_XLARGE + - :REDIS_STANDARD_SMALL + default_from_api: true + immutable: true + required: false - !ruby/object:Api::Type::Array name: 'pscConfigs' description: | @@ -208,6 +221,11 @@ properties: description: | Output only. Redis memory size in GB for the entire cluster. output: true + - !ruby/object:Api::Type::Double + name: preciseSizeGb + description: | + Output only. Redis memory precise size in GB for the entire cluster. + output: true - !ruby/object:Api::Type::Integer name: shardCount description: | diff --git a/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb b/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb index a2ef9d488324..24273a469e55 100644 --- a/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb +++ b/mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb @@ -6,6 +6,7 @@ resource "google_redis_cluster" "<%= ctx[:primary_resource_id] %>" { } region = "us-central1" replica_count = 1 + node_type = "REDIS_SHARED_CORE_NANO" transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED" authorization_mode = "AUTH_MODE_DISABLED" depends_on = [ diff --git a/mmv1/third_party/terraform/services/redis/resource_redis_cluster_test.go.erb b/mmv1/third_party/terraform/services/redis/resource_redis_cluster_test.go.erb index b84720d92321..928eb49c857c 100644 --- a/mmv1/third_party/terraform/services/redis/resource_redis_cluster_test.go.erb +++ b/mmv1/third_party/terraform/services/redis/resource_redis_cluster_test.go.erb @@ -10,6 +10,34 @@ import ( "github.com/hashicorp/terraform-provider-google/google/acctest" ) +func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) { + t.Parallel() + + name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t)) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + CheckDestroy: testAccCheckRedisClusterDestroyProducer(t), + Steps: []resource.TestStep{ + { + // create cluster with replica count 1 + Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 1, /* shardCount = */ 3, true, /*nodeType = */ "REDIS_STANDARD_SMALL"), + }, + { + ResourceName: "google_redis_cluster.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"psc_configs"}, + }, + { + // clean up the resource + Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 0, /* shardCount = */ 3, false, /*nodeType = */ "REDIS_STANDARD_SMALL"), + }, + }, + }) +} + // Validate that replica count is updated for the cluster func TestAccRedisCluster_updateReplicaCount(t *testing.T) { t.Parallel() @@ -23,7 +51,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) { Steps: []resource.TestStep{ { // create cluster with replica count 1 - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true), + Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 1, /* shardCount = */ 3, true, /* nodeType = */ ""), }, { ResourceName: "google_redis_cluster.test", @@ -33,7 +61,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) { }, { // update replica count to 2 - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 2 /* shardCount = */, 3, true), + Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 2, /* shardCount = */ 3, true, /*nodeType = */ ""), }, { ResourceName: "google_redis_cluster.test", @@ -43,11 +71,11 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) { }, { // clean up the resource - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 2 /* shardCount = */, 3, false), + Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 2, /* shardCount = */ 3, false, /*nodeType = */ ""), }, { // update replica count to 0 - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, true), + Config: createOrUpdateRedisCluster(name, /* replicaCount = */ 0, /* shardCount = */ 3, true, /*nodeType = */ ""), }, { ResourceName: "google_redis_cluster.test", @@ -57,7 +85,7 @@ func TestAccRedisCluster_updateReplicaCount(t *testing.T) { }, { // clean up the resource - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false), + Config: createOrUpdateRedisCluster(name /* replicaCount = */, 0 /* shardCount = */, 3, false, /*nodeType = */ ""), }, }, }) @@ -76,7 +104,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) { Steps: []resource.TestStep{ { // create cluster with shard count 3 - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true), + Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 3, true, /*nodeType = */ ""), }, { ResourceName: "google_redis_cluster.test", @@ -87,7 +115,7 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) { }, { // update shard count to 5 - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, true), + Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, true, /*nodeType = */ ""), }, { ResourceName: "google_redis_cluster.test", @@ -97,13 +125,13 @@ func TestAccRedisCluster_updateShardCount(t *testing.T) { }, { // clean up the resource - Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, false), + Config: createOrUpdateRedisCluster(name /* replicaCount = */, 1 /* shardCount = */, 5, false, /* nodeType = */ ""), }, }, }) } -func createOrUpdateRedisCluster(name string, replicaCount int, shardCount int, preventDestroy bool) string { +func createOrUpdateRedisCluster(name string, replicaCount int, shardCount int, preventDestroy bool, nodeType string) string { lifecycleBlock := "" if preventDestroy { lifecycleBlock = ` @@ -117,6 +145,7 @@ resource "google_redis_cluster" "test" { name = "%s" replica_count = %d shard_count = %d + node_type = "%s" region = "us-central1" psc_configs { network = google_compute_network.producer_net.id @@ -152,6 +181,6 @@ resource "google_compute_network" "producer_net" { name = "%s" auto_create_subnetworks = false } -`, name, replicaCount, shardCount, lifecycleBlock, name, name, name) +`, name, replicaCount, shardCount, nodeType, lifecycleBlock, name, name, name) } <% end -%>