@@ -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
1442func 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}
0 commit comments