@@ -1817,3 +1817,63 @@ resource "google_compute_network" "default" {
18171817}
18181818` , context )
18191819}
1820+
1821+ // Ensures cluster update does not throw errors for not specifying initial user after create
1822+ func TestAccAlloydbCluster_randomPassword (t * testing.T ) {
1823+ // Random provider causes VCR to fail
1824+ acctest .SkipIfVcr (t )
1825+ t .Parallel ()
1826+ context := map [string ]interface {}{
1827+ "random_suffix" : acctest .RandString (t , 10 ),
1828+ }
1829+
1830+ acctest .VcrTest (t , resource.TestCase {
1831+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1832+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
1833+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
1834+ ExternalProviders : map [string ]resource.ExternalProvider {
1835+ "random" : {},
1836+ },
1837+ Steps : []resource.TestStep {
1838+ {
1839+ Config : testAccAlloydbCluster_randomPassword (context ),
1840+ },
1841+ {
1842+ ResourceName : "google_alloydb_cluster.default" ,
1843+ ImportState : true ,
1844+ ImportStateVerify : true ,
1845+ ImportStateVerifyIgnore : []string {"deletion_protection" , "initial_user" , "cluster_id" , "location" },
1846+ },
1847+ },
1848+ })
1849+ }
1850+
1851+ func testAccAlloydbCluster_randomPassword (context map [string ]interface {}) string {
1852+ return acctest .Nprintf (`
1853+ resource "google_alloydb_cluster" "default" {
1854+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
1855+ location = "us-central1"
1856+ network_config {
1857+ network = google_compute_network.default.id
1858+ }
1859+
1860+ initial_user {
1861+ password = random_string.random.result
1862+ }
1863+
1864+ deletion_protection = false
1865+
1866+ lifecycle {
1867+ prevent_destroy = false
1868+ }
1869+ }
1870+
1871+ resource "random_string" "random" {
1872+ length = 16
1873+ }
1874+
1875+ resource "google_compute_network" "default" {
1876+ name = "tf-test-alloydb-cluster%{random_suffix}"
1877+ }
1878+ ` , context )
1879+ }
0 commit comments