@@ -293,7 +293,7 @@ func TestAccAlloydbCluster_addAutomatedBackupPolicyAndInitialUser(t *testing.T)
293293 CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
294294 Steps : []resource.TestStep {
295295 {
296- Config : testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context ),
296+ Config : testAccAlloydbCluster_withoutAutomatedBackupPolicy (context ),
297297 },
298298 {
299299 ResourceName : "google_alloydb_cluster.default" ,
@@ -343,7 +343,7 @@ func TestAccAlloydbCluster_deleteAutomatedBackupPolicyAndInitialUser(t *testing.
343343 ImportStateVerifyIgnore : []string {"deletion_protection" , "initial_user" , "cluster_id" , "location" },
344344 },
345345 {
346- Config : testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context ),
346+ Config : testAccAlloydbCluster_withoutAutomatedBackupPolicy (context ),
347347 },
348348 {
349349 ResourceName : "google_alloydb_cluster.default" ,
@@ -444,7 +444,7 @@ resource "google_compute_network" "default" {
444444` , context )
445445}
446446
447- func testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context map [string ]interface {}) string {
447+ func testAccAlloydbCluster_withoutAutomatedBackupPolicy (context map [string ]interface {}) string {
448448 return acctest .Nprintf (`
449449resource "google_alloydb_cluster" "default" {
450450 cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
@@ -1749,3 +1749,71 @@ func TestAccAlloydbCluster_standardClusterUpdateFailure(t *testing.T) {
17491749 },
17501750 })
17511751}
1752+
1753+ // Ensures cluster throws expected errors for not specifying initial user on create
1754+ func TestAccAlloydbCluster_withoutInitialUserFailure (t * testing.T ) {
1755+ t .Parallel ()
1756+ errorPattern := `New AlloyDB Clusters must have initial_user.password specified`
1757+ context := map [string ]interface {}{
1758+ "random_suffix" : acctest .RandString (t , 10 ),
1759+ }
1760+
1761+ acctest .VcrTest (t , resource.TestCase {
1762+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1763+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1764+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1765+ Steps : []resource.TestStep {
1766+ {
1767+ Config : testAccAlloydbCluster_withoutInitialUser (context ),
1768+ ExpectError : regexp .MustCompile (errorPattern ),
1769+ },
1770+ },
1771+ })
1772+ }
1773+
1774+ // Ensures cluster update does not throw errors for not specifying initial user after create
1775+ func TestAccAlloydbCluster_withoutInitialUserUpdate (t * testing.T ) {
1776+ t .Parallel ()
1777+ context := map [string ]interface {}{
1778+ "random_suffix" : acctest .RandString (t , 10 ),
1779+ }
1780+
1781+ acctest .VcrTest (t , resource.TestCase {
1782+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1783+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1784+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1785+ Steps : []resource.TestStep {
1786+ {
1787+ Config : testAccAlloydbCluster_alloydbClusterBasicExample (context ),
1788+ },
1789+ {
1790+ Config : testAccAlloydbCluster_withoutInitialUser (context ),
1791+ },
1792+ },
1793+ })
1794+ }
1795+
1796+ func testAccAlloydbCluster_withoutInitialUser (context map [string ]interface {}) string {
1797+ return acctest .Nprintf (`
1798+ resource "google_alloydb_cluster" "default" {
1799+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
1800+ location = "us-central1"
1801+ network_config {
1802+ network = google_compute_network.default.id
1803+ }
1804+
1805+ deletion_protection = false
1806+
1807+ lifecycle {
1808+ prevent_destroy = false
1809+ }
1810+ }
1811+
1812+ data "google_project" "project" {
1813+ }
1814+
1815+ resource "google_compute_network" "default" {
1816+ name = "tf-test-alloydb-cluster%{random_suffix}"
1817+ }
1818+ ` , context )
1819+ }
0 commit comments