@@ -309,7 +309,7 @@ func TestAccAlloydbCluster_addAutomatedBackupPolicyAndInitialUser(t *testing.T)
309309 CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
310310 Steps : []resource.TestStep {
311311 {
312- Config : testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context ),
312+ Config : testAccAlloydbCluster_withoutAutomatedBackupPolicy (context ),
313313 },
314314 {
315315 ResourceName : "google_alloydb_cluster.default" ,
@@ -359,7 +359,7 @@ func TestAccAlloydbCluster_deleteAutomatedBackupPolicyAndInitialUser(t *testing.
359359 ImportStateVerifyIgnore : []string {"deletion_protection" , "initial_user" , "cluster_id" , "location" },
360360 },
361361 {
362- Config : testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context ),
362+ Config : testAccAlloydbCluster_withoutAutomatedBackupPolicy (context ),
363363 },
364364 {
365365 ResourceName : "google_alloydb_cluster.default" ,
@@ -460,7 +460,7 @@ resource "google_compute_network" "default" {
460460` , context )
461461}
462462
463- func testAccAlloydbCluster_withoutInitialUserAndAutomatedBackupPolicy (context map [string ]interface {}) string {
463+ func testAccAlloydbCluster_withoutAutomatedBackupPolicy (context map [string ]interface {}) string {
464464 return acctest .Nprintf (`
465465resource "google_alloydb_cluster" "default" {
466466 cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
@@ -1765,3 +1765,71 @@ func TestAccAlloydbCluster_standardClusterUpdateFailure(t *testing.T) {
17651765 },
17661766 })
17671767}
1768+
1769+ // Ensures cluster throws expected errors for not specifying initial user on create
1770+ func TestAccAlloydbCluster_withoutInitialUserFailure (t * testing.T ) {
1771+ t .Parallel ()
1772+ errorPattern := `New AlloyDB Clusters must have initial_user.password specified`
1773+ context := map [string ]interface {}{
1774+ "random_suffix" : acctest .RandString (t , 10 ),
1775+ }
1776+
1777+ acctest .VcrTest (t , resource.TestCase {
1778+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1779+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1780+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1781+ Steps : []resource.TestStep {
1782+ {
1783+ Config : testAccAlloydbCluster_withoutInitialUser (context ),
1784+ ExpectError : regexp .MustCompile (errorPattern ),
1785+ },
1786+ },
1787+ })
1788+ }
1789+
1790+ // Ensures cluster update does not throw errors for not specifying initial user after create
1791+ func TestAccAlloydbCluster_withoutInitialUserUpdate (t * testing.T ) {
1792+ t .Parallel ()
1793+ context := map [string ]interface {}{
1794+ "random_suffix" : acctest .RandString (t , 10 ),
1795+ }
1796+
1797+ acctest .VcrTest (t , resource.TestCase {
1798+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1799+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1800+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1801+ Steps : []resource.TestStep {
1802+ {
1803+ Config : testAccAlloydbCluster_alloydbClusterBasicExample (context ),
1804+ },
1805+ {
1806+ Config : testAccAlloydbCluster_withoutInitialUser (context ),
1807+ },
1808+ },
1809+ })
1810+ }
1811+
1812+ func testAccAlloydbCluster_withoutInitialUser (context map [string ]interface {}) string {
1813+ return acctest .Nprintf (`
1814+ resource "google_alloydb_cluster" "default" {
1815+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
1816+ location = "us-central1"
1817+ network_config {
1818+ network = google_compute_network.default.id
1819+ }
1820+
1821+ deletion_protection = false
1822+
1823+ lifecycle {
1824+ prevent_destroy = false
1825+ }
1826+ }
1827+
1828+ data "google_project" "project" {
1829+ }
1830+
1831+ resource "google_compute_network" "default" {
1832+ name = "tf-test-alloydb-cluster%{random_suffix}"
1833+ }
1834+ ` , context )
1835+ }
0 commit comments