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