@@ -221,3 +221,130 @@ resource "google_alloydb_user" "user2" {
221221 depends_on = [google_alloydb_instance.default]
222222}` , context )
223223}
224+
225+ func TestAccAlloydbUser_alloydbUserBuiltinWithPasswordWo (t * testing.T ) {
226+ t .Parallel ()
227+
228+ context := map [string ]interface {}{
229+ "network_name" : acctest .BootstrapSharedServiceNetworkingConnection (t , "alloydb-1" ),
230+ "random_suffix" : acctest .RandString (t , 10 ),
231+ }
232+
233+ acctest .VcrTest (t , resource.TestCase {
234+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
235+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
236+ CheckDestroy : testAccCheckAlloydbUserDestroyProducer (t ),
237+ Steps : []resource.TestStep {
238+ {
239+ Config : testAccAlloydbUser_alloydbUserBuiltinWithPasswordWo (context ),
240+ Check : resource .ComposeTestCheckFunc (
241+ resource .TestCheckNoResourceAttr ("google_alloydb_user.user1" , "password_wo" ),
242+ resource .TestCheckResourceAttr ("google_alloydb_user.user1" , "password_wo_version" , "1" ),
243+ ),
244+ },
245+ {
246+ ResourceName : "google_alloydb_user.user1" ,
247+ ImportState : true ,
248+ ImportStateVerify : true ,
249+ ImportStateVerifyIgnore : []string {"password" },
250+ },
251+ },
252+ })
253+ }
254+
255+ func testAccAlloydbUser_alloydbUserBuiltinWithPasswordWo (context map [string ]interface {}) string {
256+ return acctest .Nprintf (`
257+ resource "google_alloydb_instance" "default" {
258+ cluster = google_alloydb_cluster.default.name
259+ instance_id = "tf-test-alloydb-instance%{random_suffix}"
260+ instance_type = "PRIMARY"
261+ }
262+ resource "google_alloydb_cluster" "default" {
263+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
264+ location = "us-central1"
265+ network_config {
266+ network = data.google_compute_network.default.id
267+ }
268+ initial_user {
269+ password = "tf_test_cluster_secret%{random_suffix}"
270+ }
271+ deletion_protection = false
272+ }
273+ data "google_project" "project" {}
274+ data "google_compute_network" "default" {
275+ name = "%{network_name}"
276+ }
277+ resource "google_alloydb_user" "user1" {
278+ cluster = google_alloydb_cluster.default.name
279+ user_id = "user1%{random_suffix}"
280+ user_type = "ALLOYDB_BUILT_IN"
281+ password_wo = "tf_test_user_secret%{random_suffix}"
282+ password_wo_version = 1
283+ database_roles = ["alloydbsuperuser"]
284+ depends_on = [google_alloydb_instance.default]
285+ }` , context )
286+ }
287+
288+ func TestAccAlloydbUser_alloydbUserBuiltinWithPasswordWo_update (t * testing.T ) {
289+ t .Parallel ()
290+
291+ context := map [string ]interface {}{
292+ "network_name" : acctest .BootstrapSharedServiceNetworkingConnection (t , "alloydb-1" ),
293+ "random_suffix" : acctest .RandString (t , 10 ),
294+ }
295+
296+ acctest .VcrTest (t , resource.TestCase {
297+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
298+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
299+ CheckDestroy : testAccCheckAlloydbUserDestroyProducer (t ),
300+ Steps : []resource.TestStep {
301+ {
302+ Config : testAccAlloydbUser_alloydbUserBuiltinWithPasswordWo (context ),
303+ Check : resource .ComposeTestCheckFunc (
304+ resource .TestCheckNoResourceAttr ("google_alloydb_user.user1" , "password_wo" ),
305+ resource .TestCheckResourceAttr ("google_alloydb_user.user1" , "password_wo_version" , "1" ),
306+ ),
307+ },
308+ {
309+ Config : testAccAlloydbUser_alloydbUserBuiltinWithPasswordWo_update (context ),
310+ Check : resource .ComposeTestCheckFunc (
311+ resource .TestCheckNoResourceAttr ("google_alloydb_user.user1" , "password_wo" ),
312+ resource .TestCheckResourceAttr ("google_alloydb_user.user1" , "password_wo_version" , "2" ),
313+ ),
314+ },
315+ },
316+ })
317+ }
318+
319+ func testAccAlloydbUser_alloydbUserBuiltinWithPasswordWo_update (context map [string ]interface {}) string {
320+ return acctest .Nprintf (`
321+ resource "google_alloydb_instance" "default" {
322+ cluster = google_alloydb_cluster.default.name
323+ instance_id = "tf-test-alloydb-instance%{random_suffix}"
324+ instance_type = "PRIMARY"
325+ }
326+ resource "google_alloydb_cluster" "default" {
327+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
328+ location = "us-central1"
329+ network_config {
330+ network = data.google_compute_network.default.id
331+ }
332+ initial_user {
333+ password = "tf_test_cluster_secret%{random_suffix}"
334+ }
335+ deletion_protection = false
336+ }
337+ data "google_project" "project" {}
338+ data "google_compute_network" "default" {
339+ name = "%{network_name}"
340+ }
341+ resource "google_alloydb_user" "user1" {
342+ cluster = google_alloydb_cluster.default.name
343+ user_id = "user1%{random_suffix}"
344+ user_type = "ALLOYDB_BUILT_IN"
345+ password_wo = "tf_test_user_updated_secret%{random_suffix}"
346+ password_wo_version = 2
347+ database_roles = ["alloydbsuperuser"]
348+ depends_on = [google_alloydb_instance.default]
349+ }` , context )
350+ }
0 commit comments