@@ -22,6 +22,9 @@ func TestAccAlloydbCluster_update(t *testing.T) {
22
22
Steps : []resource.TestStep {
23
23
{
24
24
Config : testAccAlloydbCluster_alloydbClusterBasicExample (context ),
25
+ Check : resource .ComposeTestCheckFunc (
26
+ resource .TestCheckResourceAttr ("google_alloydb_cluster.default" , "subscription_type" , "STANDARD" ),
27
+ ),
25
28
},
26
29
{
27
30
ResourceName : "google_alloydb_cluster.default" ,
@@ -72,6 +75,94 @@ resource "google_compute_network" "default" {
72
75
` , context )
73
76
}
74
77
78
+ // Trial cluster creation should succeed with subscription type field set to Trial.
79
+ func TestAccAlloydbCluster_withSubscriptionTypeTrial (t * testing.T ) {
80
+ t .Parallel ()
81
+
82
+ context := map [string ]interface {}{
83
+ "random_suffix" : acctest .RandString (t , 10 ),
84
+ }
85
+
86
+ acctest .VcrTest (t , resource.TestCase {
87
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
88
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
89
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
90
+ Steps : []resource.TestStep {
91
+ {
92
+ Config : testAccAlloydbCluster_withSubscriptionTypeTrial (context ),
93
+ Check : resource .ComposeTestCheckFunc (
94
+ resource .TestCheckResourceAttr ("google_alloydb_cluster.default" , "subscription_type" , "TRIAL" ),
95
+ resource .TestMatchResourceAttr ("google_alloydb_cluster.default" , "trial_metadata.0.start_time" , regexp .MustCompile (".+" )),
96
+ resource .TestMatchResourceAttr ("google_alloydb_cluster.default" , "trial_metadata.0.end_time" , regexp .MustCompile (".+" )),
97
+ ),
98
+ },
99
+ },
100
+ })
101
+ }
102
+
103
+ func testAccAlloydbCluster_withSubscriptionTypeTrial (context map [string ]interface {}) string {
104
+ return acctest .Nprintf (`
105
+ resource "google_alloydb_cluster" "default" {
106
+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
107
+ location = "us-central1"
108
+ subscription_type = "TRIAL"
109
+ network_config {
110
+ network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
111
+ }
112
+ }
113
+
114
+ data "google_project" "project" {
115
+ }
116
+
117
+ resource "google_compute_network" "default" {
118
+ name = "tf-test-alloydb-cluster%{random_suffix}"
119
+ }
120
+ ` , context )
121
+ }
122
+
123
+ // Standard cluster creation should succeed with subscription type field set to Standard.
124
+ func TestAccAlloydbCluster_withSubscriptionTypeStandard (t * testing.T ) {
125
+ t .Parallel ()
126
+
127
+ context := map [string ]interface {}{
128
+ "random_suffix" : acctest .RandString (t , 10 ),
129
+ }
130
+
131
+ acctest .VcrTest (t , resource.TestCase {
132
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
133
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
134
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
135
+ Steps : []resource.TestStep {
136
+ {
137
+ Config : testAccAlloydbCluster_withSubscriptionTypeStandard (context ),
138
+ Check : resource .ComposeTestCheckFunc (
139
+ resource .TestCheckResourceAttr ("google_alloydb_cluster.default" , "subscription_type" , "STANDARD" ),
140
+ ),
141
+ },
142
+ },
143
+ })
144
+ }
145
+
146
+ func testAccAlloydbCluster_withSubscriptionTypeStandard (context map [string ]interface {}) string {
147
+ return acctest .Nprintf (`
148
+ resource "google_alloydb_cluster" "default" {
149
+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
150
+ location = "us-central1"
151
+ subscription_type = "STANDARD"
152
+ network_config {
153
+ network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
154
+ }
155
+ }
156
+
157
+ data "google_project" "project" {
158
+ }
159
+
160
+ resource "google_compute_network" "default" {
161
+ name = "tf-test-alloydb-cluster%{random_suffix}"
162
+ }
163
+ ` , context )
164
+ }
165
+
75
166
// Test if adding automatedBackupPolicy AND initialUser re-creates the cluster.
76
167
// Ideally, cluster shouldn't be re-created. This test will only pass if the cluster
77
168
// isn't re-created but updated in-place.
@@ -1363,3 +1454,118 @@ resource "google_alloydb_cluster" "default" {
1363
1454
data "google_project" "project" {}
1364
1455
` , context )
1365
1456
}
1457
+
1458
+ // Ensures cluster update from unspecified to standard and standard to standard works with no change in config.
1459
+ func TestAccAlloydbCluster_standardClusterUpdate (t * testing.T ) {
1460
+ t .Parallel ()
1461
+
1462
+ context := map [string ]interface {}{
1463
+ "random_suffix" : acctest .RandString (t , 10 ),
1464
+ }
1465
+
1466
+ acctest .VcrTest (t , resource.TestCase {
1467
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1468
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1469
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1470
+ Steps : []resource.TestStep {
1471
+ {
1472
+ Config : testAccAlloydbCluster_alloydbClusterBasicExample (context ),
1473
+ Check : resource .ComposeTestCheckFunc (
1474
+ resource .TestCheckResourceAttr ("google_alloydb_cluster.default" , "subscription_type" , "STANDARD" ),
1475
+ ),
1476
+ },
1477
+ {
1478
+ ResourceName : "google_alloydb_cluster.default" ,
1479
+ ImportState : true ,
1480
+ ImportStateVerify : true ,
1481
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
1482
+ },
1483
+ {
1484
+ Config : testAccAlloydbCluster_withSubscriptionTypeStandard (context ),
1485
+ },
1486
+ {
1487
+ ResourceName : "google_alloydb_cluster.default" ,
1488
+ ImportState : true ,
1489
+ ImportStateVerify : true ,
1490
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
1491
+ },
1492
+ {
1493
+ Config : testAccAlloydbCluster_withSubscriptionTypeStandard (context ),
1494
+ },
1495
+ {
1496
+ ResourceName : "google_alloydb_cluster.default" ,
1497
+ ImportState : true ,
1498
+ ImportStateVerify : true ,
1499
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
1500
+ },
1501
+ },
1502
+ })
1503
+ }
1504
+
1505
+ // Ensures cluster update succeeds with subscription type from trial to standard and trial to trial results in no change in config.
1506
+ func TestAccAlloydbCluster_trialClusterUpdate (t * testing.T ) {
1507
+ t .Parallel ()
1508
+
1509
+ context := map [string ]interface {}{
1510
+ "random_suffix" : acctest .RandString (t , 10 ),
1511
+ }
1512
+
1513
+ acctest .VcrTest (t , resource.TestCase {
1514
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1515
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1516
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1517
+ Steps : []resource.TestStep {
1518
+ {
1519
+ Config : testAccAlloydbCluster_withSubscriptionTypeTrial (context ),
1520
+ },
1521
+ {
1522
+ ResourceName : "google_alloydb_cluster.default" ,
1523
+ ImportState : true ,
1524
+ ImportStateVerify : true ,
1525
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
1526
+ },
1527
+ {
1528
+ Config : testAccAlloydbCluster_withSubscriptionTypeTrial (context ),
1529
+ },
1530
+ {
1531
+ ResourceName : "google_alloydb_cluster.default" ,
1532
+ ImportState : true ,
1533
+ ImportStateVerify : true ,
1534
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
1535
+ },
1536
+ {
1537
+ Config : testAccAlloydbCluster_withSubscriptionTypeStandard (context ),
1538
+ },
1539
+ {
1540
+ ResourceName : "google_alloydb_cluster.default" ,
1541
+ ImportState : true ,
1542
+ ImportStateVerify : true ,
1543
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
1544
+ },
1545
+ },
1546
+ })
1547
+ }
1548
+
1549
+ // Ensures cluster update throws expected errors for subscription update from standard to trial.
1550
+ func TestAccAlloydbCluster_standardClusterUpdateFailure (t * testing.T ) {
1551
+ t .Parallel ()
1552
+ errorPattern := `.*The request was invalid: invalid subscription_type update`
1553
+ context := map [string ]interface {}{
1554
+ "random_suffix" : acctest .RandString (t , 10 ),
1555
+ }
1556
+
1557
+ acctest .VcrTest (t , resource.TestCase {
1558
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1559
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1560
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1561
+ Steps : []resource.TestStep {
1562
+ {
1563
+ Config : testAccAlloydbCluster_withSubscriptionTypeStandard (context ),
1564
+ },
1565
+ {
1566
+ Config : testAccAlloydbCluster_withSubscriptionTypeTrial (context ),
1567
+ ExpectError : regexp .MustCompile (errorPattern ),
1568
+ },
1569
+ },
1570
+ })
1571
+ }
0 commit comments