@@ -67,3 +67,153 @@ resource "google_compute_network" "default" {
67
67
}
68
68
` , context )
69
69
}
70
+
71
+ // Test if adding automatedBackupPolicy AND initialUser re-creates the cluster.
72
+ // Ideally, cluster shouldn't be re-created. This test will only pass if the cluster
73
+ // isn't re-created but updated in-place.
74
+ func TestAccAlloydbCluster_addAutomatedBackupPolicyAndInitialUser (t * testing.T ) {
75
+ t .Parallel ()
76
+
77
+ context := map [string ]interface {}{
78
+ "random_suffix" : RandString (t , 10 ),
79
+ }
80
+
81
+ VcrTest (t , resource.TestCase {
82
+ PreCheck : func () { testAccPreCheck (t ) },
83
+ ProtoV5ProviderFactories : ProtoV5ProviderFactories (t ),
84
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
85
+ Steps : []resource.TestStep {
86
+ {
87
+ Config : testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context ),
88
+ },
89
+ {
90
+ ResourceName : "google_alloydb_cluster.default" ,
91
+ ImportState : true ,
92
+ ImportStateVerify : true ,
93
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
94
+ },
95
+ {
96
+ Config : testAccAlloydbCluster_withInitialUserAndAutomatedBackupPolicy (context ),
97
+ },
98
+ {
99
+ ResourceName : "google_alloydb_cluster.default" ,
100
+ ImportState : true ,
101
+ ImportStateVerify : true ,
102
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
103
+ },
104
+ {
105
+ Config : testAccAlloydbCluster_alloydbClusterBasicExample (context ),
106
+ },
107
+ },
108
+ })
109
+ }
110
+
111
+ // Test if deleting automatedBackupPolicy AND initialUser re-creates the cluster.
112
+ // Ideally, cluster shouldn't be re-created. This test will only pass if the cluster
113
+ // isn't re-created but updated in-place.
114
+ func TestAccAlloydbCluster_deleteAutomatedBackupPolicyAndInitialUser (t * testing.T ) {
115
+ t .Parallel ()
116
+
117
+ context := map [string ]interface {}{
118
+ "random_suffix" : RandString (t , 10 ),
119
+ }
120
+
121
+ VcrTest (t , resource.TestCase {
122
+ PreCheck : func () { testAccPreCheck (t ) },
123
+ ProtoV5ProviderFactories : ProtoV5ProviderFactories (t ),
124
+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
125
+ Steps : []resource.TestStep {
126
+ {
127
+ Config : testAccAlloydbCluster_withInitialUserAndAutomatedBackupPolicy (context ),
128
+ },
129
+ {
130
+ ResourceName : "google_alloydb_cluster.default" ,
131
+ ImportState : true ,
132
+ ImportStateVerify : true ,
133
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
134
+ },
135
+ {
136
+ Config : testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context ),
137
+ },
138
+ {
139
+ ResourceName : "google_alloydb_cluster.default" ,
140
+ ImportState : true ,
141
+ ImportStateVerify : true ,
142
+ ImportStateVerifyIgnore : []string {"initial_user" , "cluster_id" , "location" },
143
+ },
144
+ {
145
+ Config : testAccAlloydbCluster_alloydbClusterBasicExample (context ),
146
+ },
147
+ },
148
+ })
149
+ }
150
+
151
+ func testAccAlloydbCluster_withInitialUserAndAutomatedBackupPolicy (context map [string ]interface {}) string {
152
+ return Nprintf (`
153
+ resource "google_alloydb_cluster" "default" {
154
+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
155
+ location = "us-central1"
156
+ network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
157
+
158
+ initial_user {
159
+ user = "tf-test-alloydb-cluster%{random_suffix}"
160
+ password = "tf-test-alloydb-cluster%{random_suffix}"
161
+ }
162
+
163
+ automated_backup_policy {
164
+ location = "us-central1"
165
+ backup_window = "1800s"
166
+ enabled = true
167
+
168
+ weekly_schedule {
169
+ days_of_week = ["MONDAY"]
170
+
171
+ start_times {
172
+ hours = 23
173
+ minutes = 0
174
+ seconds = 0
175
+ nanos = 0
176
+ }
177
+ }
178
+
179
+ quantity_based_retention {
180
+ count = 1
181
+ }
182
+
183
+ labels = {
184
+ test = "tf-test-alloydb-cluster%{random_suffix}"
185
+ }
186
+ }
187
+ lifecycle {
188
+ prevent_destroy = true
189
+ }
190
+ }
191
+
192
+ data "google_project" "project" {
193
+ }
194
+
195
+ resource "google_compute_network" "default" {
196
+ name = "tf-test-alloydb-cluster%{random_suffix}"
197
+ }
198
+ ` , context )
199
+ }
200
+
201
+ func testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context map [string ]interface {}) string {
202
+ return Nprintf (`
203
+ resource "google_alloydb_cluster" "default" {
204
+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
205
+ location = "us-central1"
206
+ network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
207
+ lifecycle {
208
+ prevent_destroy = true
209
+ }
210
+ }
211
+
212
+ data "google_project" "project" {
213
+ }
214
+
215
+ resource "google_compute_network" "default" {
216
+ name = "tf-test-alloydb-cluster%{random_suffix}"
217
+ }
218
+ ` , context )
219
+ }
0 commit comments