Skip to content

Commit

Permalink
Adding nodeType field in the terraform (GoogleCloudPlatform#10090)
Browse files Browse the repository at this point in the history
  • Loading branch information
shailymittal-github authored and pawelJas committed May 16, 2024
1 parent f70ad27 commit a7b917e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
18 changes: 18 additions & 0 deletions mmv1/products/redis/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions mmv1/templates/terraform/examples/redis_cluster_ha.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 = */ ""),
},
},
})
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 = `
Expand All @@ -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
Expand Down Expand Up @@ -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 -%>

0 comments on commit a7b917e

Please sign in to comment.