Skip to content

Commit 4512737

Browse files
Update AlloyDB tests to use bootstrapped networks (#14160) (#23100)
[upstream:3179dc4005ab3c7f08c5f060d7a35e57218e8078] Signed-off-by: Modular Magician <[email protected]>
1 parent 2aa4231 commit 4512737

File tree

4 files changed

+12
-159
lines changed

4 files changed

+12
-159
lines changed

google/services/alloydb/resource_alloydb_backup_generated_test.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -86,82 +86,6 @@ data "google_compute_network" "default" {
8686
`, context)
8787
}
8888

89-
func TestAccAlloydbBackup_alloydbBackupFullExample(t *testing.T) {
90-
t.Parallel()
91-
92-
context := map[string]interface{}{
93-
"random_suffix": acctest.RandString(t, 10),
94-
}
95-
96-
acctest.VcrTest(t, resource.TestCase{
97-
PreCheck: func() { acctest.AccTestPreCheck(t) },
98-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
99-
CheckDestroy: testAccCheckAlloydbBackupDestroyProducer(t),
100-
Steps: []resource.TestStep{
101-
{
102-
Config: testAccAlloydbBackup_alloydbBackupFullExample(context),
103-
},
104-
{
105-
ResourceName: "google_alloydb_backup.default",
106-
ImportState: true,
107-
ImportStateVerify: true,
108-
ImportStateVerifyIgnore: []string{"annotations", "backup_id", "labels", "location", "reconciling", "terraform_labels", "update_time"},
109-
},
110-
},
111-
})
112-
}
113-
114-
func testAccAlloydbBackup_alloydbBackupFullExample(context map[string]interface{}) string {
115-
return acctest.Nprintf(`
116-
resource "google_alloydb_backup" "default" {
117-
location = "us-central1"
118-
backup_id = "tf-test-alloydb-backup%{random_suffix}"
119-
cluster_name = google_alloydb_cluster.default.name
120-
121-
description = "example description"
122-
type = "ON_DEMAND"
123-
labels = {
124-
"label" = "key"
125-
}
126-
depends_on = [google_alloydb_instance.default]
127-
}
128-
129-
resource "google_alloydb_cluster" "default" {
130-
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
131-
location = "us-central1"
132-
network_config {
133-
network = google_compute_network.default.id
134-
}
135-
}
136-
137-
resource "google_alloydb_instance" "default" {
138-
cluster = google_alloydb_cluster.default.name
139-
instance_id = "tf-test-alloydb-instance%{random_suffix}"
140-
instance_type = "PRIMARY"
141-
142-
depends_on = [google_service_networking_connection.vpc_connection]
143-
}
144-
145-
resource "google_compute_global_address" "private_ip_alloc" {
146-
name = "tf-test-alloydb-cluster%{random_suffix}"
147-
address_type = "INTERNAL"
148-
purpose = "VPC_PEERING"
149-
prefix_length = 16
150-
network = google_compute_network.default.id
151-
}
152-
153-
resource "google_service_networking_connection" "vpc_connection" {
154-
network = google_compute_network.default.id
155-
service = "servicenetworking.googleapis.com"
156-
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
157-
}
158-
159-
resource "google_compute_network" "default" {
160-
name = "tf-test-alloydb-network%{random_suffix}"
161-
}
162-
`, context)
163-
}
164-
16589
func TestAccAlloydbBackup_alloydbBackupFullTestExample(t *testing.T) {
16690
acctest.SkipIfVcr(t)
16791
t.Parallel()

google/services/alloydb/resource_alloydb_cluster_generated_test.go

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func TestAccAlloydbCluster_alloydbClusterBeforeUpgradeExample(t *testing.T) {
7777
t.Parallel()
7878

7979
context := map[string]interface{}{
80+
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-1"),
8081
"random_suffix": acctest.RandString(t, 10),
8182
}
8283

@@ -109,14 +110,13 @@ resource "google_alloydb_instance" "default" {
109110
cpu_count = 2
110111
}
111112
112-
depends_on = [google_service_networking_connection.vpc_connection]
113113
}
114114
115115
resource "google_alloydb_cluster" "default" {
116116
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
117117
location = "us-central1"
118118
network_config {
119-
network = google_compute_network.default.id
119+
network = data.google_compute_network.default.id
120120
}
121121
database_version = "POSTGRES_14"
122122
@@ -125,24 +125,8 @@ resource "google_alloydb_cluster" "default" {
125125
}
126126
}
127127
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]
128+
data "google_compute_network" "default" {
129+
name = "%{network_name}"
146130
}
147131
`, context)
148132
}
@@ -151,6 +135,7 @@ func TestAccAlloydbCluster_alloydbClusterAfterUpgradeExample(t *testing.T) {
151135
t.Parallel()
152136

153137
context := map[string]interface{}{
138+
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-1"),
154139
"random_suffix": acctest.RandString(t, 10),
155140
}
156141

@@ -183,14 +168,13 @@ resource "google_alloydb_instance" "default" {
183168
cpu_count = 2
184169
}
185170
186-
depends_on = [google_service_networking_connection.vpc_connection]
187171
}
188172
189173
resource "google_alloydb_cluster" "default" {
190174
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
191175
location = "us-central1"
192176
network_config {
193-
network = google_compute_network.default.id
177+
network = data.google_compute_network.default.id
194178
}
195179
database_version = "POSTGRES_15"
196180
@@ -199,24 +183,8 @@ resource "google_alloydb_cluster" "default" {
199183
}
200184
}
201185
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]
186+
data "google_compute_network" "default" {
187+
name = "%{network_name}"
220188
}
221189
`, context)
222190
}

website/docs/r/alloydb_backup.html.markdown

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ resource "google_compute_network" "default" {
7676
name = "alloydb-network"
7777
}
7878
```
79-
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
80-
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=alloydb_backup_full&open_in_editor=main.tf" target="_blank">
81-
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
82-
</a>
83-
</div>
8479
## Example Usage - Alloydb Backup Full
8580

8681

website/docs/r/alloydb_cluster.html.markdown

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,13 @@ resource "google_alloydb_instance" "default" {
8686
cpu_count = 2
8787
}
8888
89-
depends_on = [google_service_networking_connection.vpc_connection]
9089
}
9190
9291
resource "google_alloydb_cluster" "default" {
9392
cluster_id = "alloydb-cluster"
9493
location = "us-central1"
9594
network_config {
96-
network = google_compute_network.default.id
95+
network = data.google_compute_network.default.id
9796
}
9897
database_version = "POSTGRES_14"
9998
@@ -102,25 +101,9 @@ resource "google_alloydb_cluster" "default" {
102101
}
103102
}
104103
105-
data "google_project" "project" {}
106-
107-
resource "google_compute_network" "default" {
104+
data "google_compute_network" "default" {
108105
name = "alloydb-network"
109106
}
110-
111-
resource "google_compute_global_address" "private_ip_alloc" {
112-
name = "alloydb-cluster"
113-
address_type = "INTERNAL"
114-
purpose = "VPC_PEERING"
115-
prefix_length = 16
116-
network = google_compute_network.default.id
117-
}
118-
119-
resource "google_service_networking_connection" "vpc_connection" {
120-
network = google_compute_network.default.id
121-
service = "servicenetworking.googleapis.com"
122-
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
123-
}
124107
```
125108
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
126109
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=alloydb_cluster_after_upgrade&open_in_editor=main.tf" target="_blank">
@@ -140,14 +123,13 @@ resource "google_alloydb_instance" "default" {
140123
cpu_count = 2
141124
}
142125
143-
depends_on = [google_service_networking_connection.vpc_connection]
144126
}
145127
146128
resource "google_alloydb_cluster" "default" {
147129
cluster_id = "alloydb-cluster"
148130
location = "us-central1"
149131
network_config {
150-
network = google_compute_network.default.id
132+
network = data.google_compute_network.default.id
151133
}
152134
database_version = "POSTGRES_15"
153135
@@ -156,25 +138,9 @@ resource "google_alloydb_cluster" "default" {
156138
}
157139
}
158140
159-
data "google_project" "project" {}
160-
161-
resource "google_compute_network" "default" {
141+
data "google_compute_network" "default" {
162142
name = "alloydb-network"
163143
}
164-
165-
resource "google_compute_global_address" "private_ip_alloc" {
166-
name = "alloydb-cluster"
167-
address_type = "INTERNAL"
168-
purpose = "VPC_PEERING"
169-
prefix_length = 16
170-
network = google_compute_network.default.id
171-
}
172-
173-
resource "google_service_networking_connection" "vpc_connection" {
174-
network = google_compute_network.default.id
175-
service = "servicenetworking.googleapis.com"
176-
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
177-
}
178144
```
179145
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
180146
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=alloydb_cluster_full&open_in_editor=main.tf" target="_blank">

0 commit comments

Comments
 (0)