@@ -73,6 +73,154 @@ resource "google_compute_network" "default" {
7373` , context )
7474}
7575
76+ func TestAccAlloydbCluster_alloydbClusterBeforeUpgradeExample (t * testing.T ) {
77+ t .Parallel ()
78+
79+ context := map [string ]interface {}{
80+ "random_suffix" : acctest .RandString (t , 10 ),
81+ }
82+
83+ acctest .VcrTest (t , resource.TestCase {
84+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
85+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
86+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
87+ Steps : []resource.TestStep {
88+ {
89+ Config : testAccAlloydbCluster_alloydbClusterBeforeUpgradeExample (context ),
90+ },
91+ {
92+ ResourceName : "google_alloydb_cluster.default" ,
93+ ImportState : true ,
94+ ImportStateVerify : true ,
95+ ImportStateVerifyIgnore : []string {"annotations" , "cluster_id" , "initial_user" , "labels" , "location" , "restore_backup_source" , "restore_continuous_backup_source" , "terraform_labels" },
96+ },
97+ },
98+ })
99+ }
100+
101+ func testAccAlloydbCluster_alloydbClusterBeforeUpgradeExample (context map [string ]interface {}) string {
102+ return acctest .Nprintf (`
103+ resource "google_alloydb_instance" "default" {
104+ cluster = google_alloydb_cluster.default.name
105+ instance_id = "tf-test-alloydb-instance%{random_suffix}"
106+ instance_type = "PRIMARY"
107+
108+ machine_config {
109+ cpu_count = 2
110+ }
111+
112+ depends_on = [google_service_networking_connection.vpc_connection]
113+ }
114+
115+ resource "google_alloydb_cluster" "default" {
116+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
117+ location = "us-central1"
118+ network_config {
119+ network = google_compute_network.default.id
120+ }
121+ database_version = "POSTGRES_14"
122+
123+ initial_user {
124+ password = "tf-test-alloydb-cluster%{random_suffix}"
125+ }
126+ }
127+
128+ data "google_project" "project" {}
129+
130+ resource "google_compute_network" "default" {
131+ name = "tf-test-alloydb-network%{random_suffix}"
132+ }
133+
134+ resource "google_compute_global_address" "private_ip_alloc" {
135+ name = "tf-test-alloydb-cluster%{random_suffix}"
136+ address_type = "INTERNAL"
137+ purpose = "VPC_PEERING"
138+ prefix_length = 16
139+ network = google_compute_network.default.id
140+ }
141+
142+ resource "google_service_networking_connection" "vpc_connection" {
143+ network = google_compute_network.default.id
144+ service = "servicenetworking.googleapis.com"
145+ reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
146+ }
147+ ` , context )
148+ }
149+
150+ func TestAccAlloydbCluster_alloydbClusterAfterUpgradeExample (t * testing.T ) {
151+ t .Parallel ()
152+
153+ context := map [string ]interface {}{
154+ "random_suffix" : acctest .RandString (t , 10 ),
155+ }
156+
157+ acctest .VcrTest (t , resource.TestCase {
158+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
159+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
160+ CheckDestroy : testAccCheckAlloydbClusterDestroyProducer (t ),
161+ Steps : []resource.TestStep {
162+ {
163+ Config : testAccAlloydbCluster_alloydbClusterAfterUpgradeExample (context ),
164+ },
165+ {
166+ ResourceName : "google_alloydb_cluster.default" ,
167+ ImportState : true ,
168+ ImportStateVerify : true ,
169+ ImportStateVerifyIgnore : []string {"annotations" , "cluster_id" , "initial_user" , "labels" , "location" , "restore_backup_source" , "restore_continuous_backup_source" , "terraform_labels" },
170+ },
171+ },
172+ })
173+ }
174+
175+ func testAccAlloydbCluster_alloydbClusterAfterUpgradeExample (context map [string ]interface {}) string {
176+ return acctest .Nprintf (`
177+ resource "google_alloydb_instance" "default" {
178+ cluster = google_alloydb_cluster.default.name
179+ instance_id = "tf-test-alloydb-instance%{random_suffix}"
180+ instance_type = "PRIMARY"
181+
182+ machine_config {
183+ cpu_count = 2
184+ }
185+
186+ depends_on = [google_service_networking_connection.vpc_connection]
187+ }
188+
189+ resource "google_alloydb_cluster" "default" {
190+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
191+ location = "us-central1"
192+ network_config {
193+ network = google_compute_network.default.id
194+ }
195+ database_version = "POSTGRES_15"
196+
197+ initial_user {
198+ password = "tf-test-alloydb-cluster%{random_suffix}"
199+ }
200+ }
201+
202+ data "google_project" "project" {}
203+
204+ resource "google_compute_network" "default" {
205+ name = "tf-test-alloydb-network%{random_suffix}"
206+ }
207+
208+ resource "google_compute_global_address" "private_ip_alloc" {
209+ name = "tf-test-alloydb-cluster%{random_suffix}"
210+ address_type = "INTERNAL"
211+ purpose = "VPC_PEERING"
212+ prefix_length = 16
213+ network = google_compute_network.default.id
214+ }
215+
216+ resource "google_service_networking_connection" "vpc_connection" {
217+ network = google_compute_network.default.id
218+ service = "servicenetworking.googleapis.com"
219+ reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
220+ }
221+ ` , context )
222+ }
223+
76224func TestAccAlloydbCluster_alloydbClusterFullExample (t * testing.T ) {
77225 t .Parallel ()
78226
0 commit comments