@@ -2,6 +2,7 @@ package cluster_test
22
33import  (
44	"fmt" 
5+ 	"regexp" 
56	"testing" 
67
78	"github.com/hashicorp/terraform-plugin-testing/helper/resource" 
@@ -16,6 +17,11 @@ func TestAccClusterResource(t *testing.T) {
1617		t .Run ("FreePlan" , testAccClusterResourceFreePlan )
1718		t .Run ("ServerlessPlan" , testAccClusterResourceServerlessPlan )
1819		t .Run ("StandardPlan" , testAccClusterResourceStandardPlan )
20+ 
21+ 		t .Run ("Plan" , func (t  * testing.T ) {
22+ 			t .Run ("UpdatePlan" , testAccClusterResourceUpdatePlan )
23+ 			t .Run ("PreventPlanDowngrade" , testAccClusterResourcePreventPlanDowngrade )
24+ 		})
1925	})
2026	t .Run ("BYOCEnv" , func (t  * testing.T ) {
2127		t .Run ("UpdateLabels" , testAccClusterResourceUpdateLabels )
@@ -53,7 +59,7 @@ resource "zillizcloud_cluster" "test" {
5359				ResourceName :            "zillizcloud_cluster.test" ,
5460				ImportState :             true ,
5561				ImportStateVerify :       true ,
56- 				ImportStateVerifyIgnore : []string {"password" , "prompt" , "username" , "replica" },
62+ 				ImportStateVerifyIgnore : []string {"password" , "prompt" , "username" , "replica" ,  "plan" },
5763				ImportStateIdFunc : func (state  * terraform.State ) (string , error ) {
5864					rs , ok  :=  state .RootModule ().Resources ["zillizcloud_cluster.test" ]
5965					if  ! ok  {
@@ -100,7 +106,7 @@ resource "zillizcloud_cluster" "test" {
100106				ResourceName :            "zillizcloud_cluster.test" ,
101107				ImportState :             true ,
102108				ImportStateVerify :       true ,
103- 				ImportStateVerifyIgnore : []string {"password" , "prompt" , "username" , "replica" },
109+ 				ImportStateVerifyIgnore : []string {"password" , "prompt" , "username" , "replica" ,  "plan" },
104110				ImportStateIdFunc : func (state  * terraform.State ) (string , error ) {
105111					rs , ok  :=  state .RootModule ().Resources ["zillizcloud_cluster.test" ]
106112					if  ! ok  {
@@ -158,7 +164,7 @@ resource "zillizcloud_cluster" "test" {
158164				ResourceName :            "zillizcloud_cluster.test" ,
159165				ImportState :             true ,
160166				ImportStateVerify :       true ,
161- 				ImportStateVerifyIgnore : []string {"password" , "prompt" , "username" },
167+ 				ImportStateVerifyIgnore : []string {"password" , "prompt" , "username" ,  "plan" },
162168				ImportStateIdFunc : func (state  * terraform.State ) (string , error ) {
163169					rs , ok  :=  state .RootModule ().Resources ["zillizcloud_cluster.test" ]
164170					if  ! ok  {
@@ -316,3 +322,132 @@ func testAccClusterResourceUpdateLabels(t *testing.T) {
316322		},
317323	})
318324}
325+ 
326+ // test update plan field 
327+ func  testAccClusterResourceUpdatePlan (t  * testing.T ) {
328+ 	t .Parallel ()
329+ 	resource .Test (t , resource.TestCase {
330+ 		ProtoV6ProviderFactories : provider .TestAccProtoV6ProviderFactories ,
331+ 		Steps : []resource.TestStep {
332+ 			{
333+ 				Config : provider .ProviderConfig  +  ` 
334+ 					data "zillizcloud_project" "default" { 
335+ 					} 
336+ 
337+ 					resource "zillizcloud_cluster" "test" { 
338+ 						cluster_name = "test-plan-update-cluster" 
339+ 						project_id   = data.zillizcloud_project.default.id 
340+ 						plan         = "Standard" 
341+ 						cu_size      = 1 
342+ 						cu_type      = "Performance-optimized" 
343+ 					} 
344+ 				` ,
345+ 				Check : resource .ComposeAggregateTestCheckFunc (
346+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cluster_name" , "test-plan-update-cluster" ),
347+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "plan" , "Standard" ),
348+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cu_size" , "1" ),
349+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cu_type" , "Performance-optimized" ),
350+ 				),
351+ 			},
352+ 			// update plan from Standard to Enterprise 
353+ 			{
354+ 				Config : provider .ProviderConfig  +  ` 
355+ 					data "zillizcloud_project" "default" { 
356+ 					} 
357+ 
358+ 					resource "zillizcloud_cluster" "test" { 
359+ 						cluster_name = "test-plan-update-cluster" 
360+ 						project_id   = data.zillizcloud_project.default.id 
361+ 						plan         = "Enterprise" 
362+ 						cu_size      = 1 
363+ 						cu_type      = "Performance-optimized" 
364+ 					} 
365+ 				` ,
366+ 				Check : resource .ComposeAggregateTestCheckFunc (
367+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cluster_name" , "test-plan-update-cluster" ),
368+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "plan" , "Enterprise" ),
369+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cu_size" , "1" ),
370+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cu_type" , "Performance-optimized" ),
371+ 				),
372+ 			},
373+ 		},
374+ 	})
375+ }
376+ 
377+ // test to prevent plan downgrade 
378+ func  testAccClusterResourcePreventPlanDowngrade (t  * testing.T ) {
379+ 	t .Parallel ()
380+ 	resource .Test (t , resource.TestCase {
381+ 		ProtoV6ProviderFactories : provider .TestAccProtoV6ProviderFactories ,
382+ 		Steps : []resource.TestStep {
383+ 			{
384+ 				Config : provider .ProviderConfig  +  ` 
385+ 					data "zillizcloud_project" "default" { 
386+ 					} 
387+ 
388+ 					resource "zillizcloud_cluster" "test" { 
389+ 						cluster_name = "test-plan-downgrade-prevention" 
390+ 						project_id   = data.zillizcloud_project.default.id 
391+ 						plan         = "Enterprise" 
392+ 						cu_size      = 1 
393+ 						cu_type      = "Performance-optimized" 
394+ 					} 
395+ 				` ,
396+ 				Check : resource .ComposeAggregateTestCheckFunc (
397+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cluster_name" , "test-plan-downgrade-prevention" ),
398+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "plan" , "Enterprise" ),
399+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cu_size" , "1" ),
400+ 					resource .TestCheckResourceAttr ("zillizcloud_cluster.test" , "cu_type" , "Performance-optimized" ),
401+ 				),
402+ 			},
403+ 			// attempt to downgrade plan from Enterprise to Standard - should fail 
404+ 			{
405+ 				Config : provider .ProviderConfig  +  ` 
406+ 					data "zillizcloud_project" "default" { 
407+ 					} 
408+ 
409+ 					resource "zillizcloud_cluster" "test" { 
410+ 						cluster_name = "test-plan-downgrade-prevention" 
411+ 						project_id   = data.zillizcloud_project.default.id 
412+ 						plan         = "Standard" 
413+ 						cu_size      = 1 
414+ 						cu_type      = "Performance-optimized" 
415+ 					} 
416+ 				` ,
417+ 				ExpectError : regexp .MustCompile ("plan downgrade is not allowed.*" ),
418+ 			},
419+ 			// attempt to downgrade plan from Enterprise to Serverless - should fail 
420+ 			{
421+ 				Config : provider .ProviderConfig  +  ` 
422+ 					data "zillizcloud_project" "default" { 
423+ 					} 
424+ 
425+ 					resource "zillizcloud_cluster" "test" { 
426+ 						cluster_name = "test-plan-downgrade-prevention" 
427+ 						project_id   = data.zillizcloud_project.default.id 
428+ 						plan         = "Serverless" 
429+ 						cu_size      = 1 
430+ 						cu_type      = "Performance-optimized" 
431+ 					} 
432+ 				` ,
433+ 				ExpectError : regexp .MustCompile ("plan downgrade is not allowed.*" ),
434+ 			},
435+ 			// attempt to downgrade plan from Enterprise to Free - should fail 
436+ 			{
437+ 				Config : provider .ProviderConfig  +  ` 
438+ 					data "zillizcloud_project" "default" { 
439+ 					} 
440+ 
441+ 					resource "zillizcloud_cluster" "test" { 
442+ 						cluster_name = "test-plan-downgrade-prevention" 
443+ 						project_id   = data.zillizcloud_project.default.id 
444+ 						plan         = "Free" 
445+ 						cu_size      = 1 
446+ 						cu_type      = "Performance-optimized" 
447+ 					} 
448+ 				` ,
449+ 				ExpectError : regexp .MustCompile ("plan downgrade is not allowed.*" ),
450+ 			},
451+ 		},
452+ 	})
453+ }
0 commit comments