@@ -14,7 +14,7 @@ func TestAccAlloydbBackup_update(t *testing.T) {
14
14
15
15
random_suffix := acctest .RandString (t , 10 )
16
16
context := map [string ]interface {}{
17
- "network_name" : "tf-test-alloydb-network" + random_suffix ,
17
+ "network_name" : acctest . BootstrapSharedServiceNetworkingConnection ( t , "alloydb-backup-update-1" ) ,
18
18
"random_suffix" : random_suffix ,
19
19
}
20
20
@@ -24,7 +24,7 @@ func TestAccAlloydbBackup_update(t *testing.T) {
24
24
CheckDestroy : testAccCheckAlloydbBackupDestroyProducer (t ),
25
25
Steps : []resource.TestStep {
26
26
{
27
- Config : testAccAlloydbBackup_alloydbBackupFullExample (context ),
27
+ Config : testAccAlloydbBackup_alloydbBackupBasic (context ),
28
28
},
29
29
{
30
30
ResourceName : "google_alloydb_backup.default" ,
@@ -45,8 +45,7 @@ func TestAccAlloydbBackup_update(t *testing.T) {
45
45
})
46
46
}
47
47
48
- // Updates "label" field from testAccAlloydbBackup_alloydbBackupFullExample
49
- func testAccAlloydbBackup_update (context map [string ]interface {}) string {
48
+ func testAccAlloydbBackup_alloydbBackupBasic (context map [string ]interface {}) string {
50
49
return acctest .Nprintf (`
51
50
resource "google_alloydb_backup" "default" {
52
51
location = "us-central1"
@@ -55,41 +54,58 @@ resource "google_alloydb_backup" "default" {
55
54
56
55
description = "example description"
57
56
labels = {
58
- "label" = "updated_key"
59
- "label2" = "updated_key2"
57
+ "label" = "key"
60
58
}
61
59
depends_on = [google_alloydb_instance.default]
62
60
}
63
61
64
62
resource "google_alloydb_cluster" "default" {
65
63
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
66
64
location = "us-central1"
67
- network = google_compute_network.default.id
65
+ network = data. google_compute_network.default.id
68
66
}
69
67
70
68
resource "google_alloydb_instance" "default" {
71
69
cluster = google_alloydb_cluster.default.name
72
70
instance_id = "tf-test-alloydb-instance%{random_suffix}"
73
71
instance_type = "PRIMARY"
72
+ }
73
+
74
+ data "google_compute_network" "default" {
75
+ name = "%{network_name}"
76
+ }
77
+ ` , context )
78
+ }
79
+
80
+ // Updates "label" field
81
+ func testAccAlloydbBackup_update (context map [string ]interface {}) string {
82
+ return acctest .Nprintf (`
83
+ resource "google_alloydb_backup" "default" {
84
+ location = "us-central1"
85
+ backup_id = "tf-test-alloydb-backup%{random_suffix}"
86
+ cluster_name = google_alloydb_cluster.default.name
74
87
75
- depends_on = [google_service_networking_connection.vpc_connection]
88
+ description = "example description"
89
+ labels = {
90
+ "label" = "updated_key"
91
+ "label2" = "updated_key2"
92
+ }
93
+ depends_on = [google_alloydb_instance.default]
76
94
}
77
95
78
- resource "google_compute_global_address" "private_ip_alloc" {
79
- name = "tf-test-alloydb-cluster%{random_suffix}"
80
- address_type = "INTERNAL"
81
- purpose = "VPC_PEERING"
82
- prefix_length = 16
83
- network = google_compute_network.default.id
96
+ resource "google_alloydb_cluster" "default" {
97
+ cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
98
+ location = "us-central1"
99
+ network = data.google_compute_network.default.id
84
100
}
85
101
86
- resource "google_service_networking_connection " "vpc_connection " {
87
- network = google_compute_network .default.id
88
- service = "servicenetworking.googleapis.com "
89
- reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
102
+ resource "google_alloydb_instance " "default " {
103
+ cluster = google_alloydb_cluster .default.name
104
+ instance_id = "tf-test-alloydb-instance%{random_suffix} "
105
+ instance_type = "PRIMARY"
90
106
}
91
107
92
- resource "google_compute_network" "default" {
108
+ data "google_compute_network" "default" {
93
109
name = "%{network_name}"
94
110
}
95
111
` , context )
@@ -101,7 +117,7 @@ func TestAccAlloydbBackup_createBackupWithMandatoryFields(t *testing.T) {
101
117
102
118
context := map [string ]interface {}{
103
119
"random_suffix" : acctest .RandString (t , 10 ),
104
- "network_name" : "tf-test-" + acctest .RandString (t , 10 ),
120
+ "network_name" : acctest .BootstrapSharedServiceNetworkingConnection (t , "alloydb-backup-mandatory-1" ),
105
121
}
106
122
107
123
acctest .VcrTest (t , resource.TestCase {
@@ -128,45 +144,19 @@ resource "google_alloydb_backup" "default" {
128
144
resource "google_alloydb_cluster" "default" {
129
145
location = "us-central1"
130
146
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
131
- network = google_compute_network.default.id
147
+ network = data. google_compute_network.default.id
132
148
}
133
149
134
150
data "google_project" "project" { }
135
151
136
- resource "google_compute_network" "default" {
152
+ data "google_compute_network" "default" {
137
153
name = "%{network_name}"
138
154
}
139
155
140
156
resource "google_alloydb_instance" "default" {
141
157
cluster = google_alloydb_cluster.default.name
142
158
instance_id = "tf-test-alloydb-instance%{random_suffix}"
143
159
instance_type = "PRIMARY"
144
-
145
- depends_on = [google_service_networking_connection.vpc_connection]
146
- }
147
-
148
- resource "google_compute_global_address" "private_ip_alloc" {
149
- name = "tf-test-alloydb-cluster%{random_suffix}"
150
- address_type = "INTERNAL"
151
- purpose = "VPC_PEERING"
152
- prefix_length = 16
153
- network = google_compute_network.default.id
154
- lifecycle {
155
- ignore_changes = [
156
- address,
157
- creation_timestamp,
158
- id,
159
- network,
160
- project,
161
- self_link
162
- ]
163
- }
164
- }
165
-
166
- resource "google_service_networking_connection" "vpc_connection" {
167
- network = google_compute_network.default.id
168
- service = "servicenetworking.googleapis.com"
169
- reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
170
160
}
171
161
` , context )
172
162
}
@@ -175,7 +165,7 @@ func TestAccAlloydbBackup_usingCMEK(t *testing.T) {
175
165
t .Parallel ()
176
166
177
167
context := map [string ]interface {}{
178
- "network_name" : "tf-test-" + acctest .RandString (t , 10 ),
168
+ "network_name" : acctest .BootstrapSharedServiceNetworkingConnection (t , "alloydb-backup-cmek-1" ),
179
169
"random_suffix" : acctest .RandString (t , 10 ),
180
170
"key_name" : "tf-test-key-" + acctest .RandString (t , 10 ),
181
171
}
@@ -218,32 +208,16 @@ resource "google_alloydb_backup" "default" {
218
208
resource "google_alloydb_cluster" "default" {
219
209
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
220
210
location = "us-central1"
221
- network = google_compute_network.default.id
211
+ network = data. google_compute_network.default.id
222
212
}
223
213
224
214
resource "google_alloydb_instance" "default" {
225
215
cluster = google_alloydb_cluster.default.name
226
216
instance_id = "tf-test-alloydb-instance%{random_suffix}"
227
217
instance_type = "PRIMARY"
228
-
229
- depends_on = [google_service_networking_connection.vpc_connection]
230
- }
231
-
232
- resource "google_compute_global_address" "private_ip_alloc" {
233
- name = "tf-test-alloydb-cluster%{random_suffix}"
234
- address_type = "INTERNAL"
235
- purpose = "VPC_PEERING"
236
- prefix_length = 16
237
- network = google_compute_network.default.id
238
- }
239
-
240
- resource "google_service_networking_connection" "vpc_connection" {
241
- network = google_compute_network.default.id
242
- service = "servicenetworking.googleapis.com"
243
- reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
244
218
}
245
219
246
- resource "google_compute_network" "default" {
220
+ data "google_compute_network" "default" {
247
221
name = "%{network_name}"
248
222
}
249
223
data "google_project" "project" {}
0 commit comments