Skip to content

Commit

Permalink
Use Create instead of Patch to create google_service_networking_conne…
Browse files Browse the repository at this point in the history
…ction (#8872) (#6222)

* Use Create instead of Patch to create google_service_networking_connection

* Remove bootstraped networks for service networking connection

* Use resource google_compute_network for tests

* Fix tests

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 7, 2023
1 parent 081d121 commit dc519fb
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 221 deletions.
4 changes: 4 additions & 0 deletions .changelog/8872.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:breaking-change
servicenetworking: used Create instead of Patch to create `google_service_networking_connection`

```
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestAccAlloydbBackup_alloydbBackupBasicExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-basic"),
"random_suffix": acctest.RandString(t, 10),
}

Expand Down Expand Up @@ -69,7 +68,7 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_alloydb_instance" "default" {
Expand All @@ -85,17 +84,17 @@ resource "google_compute_global_address" "private_ip_alloc" {
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = data.google_compute_network.default.id
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
data "google_compute_network" "default" {
name = "%{network_name}"
resource "google_compute_network" "default" {
name = "tf-test-alloydb-network%{random_suffix}"
}
`, context)
}
Expand All @@ -104,7 +103,6 @@ func TestAccAlloydbBackup_alloydbBackupFullExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-full"),
"random_suffix": acctest.RandString(t, 10),
}

Expand Down Expand Up @@ -143,7 +141,7 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_alloydb_instance" "default" {
Expand All @@ -159,17 +157,17 @@ resource "google_compute_global_address" "private_ip_alloc" {
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = data.google_compute_network.default.id
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
data "google_compute_network" "default" {
name = "%{network_name}"
resource "google_compute_network" "default" {
name = "tf-test-alloydb-network%{random_suffix}"
}
`, context)
}
Expand Down
33 changes: 17 additions & 16 deletions google-beta/services/alloydb/resource_alloydb_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
func TestAccAlloydbBackup_update(t *testing.T) {
t.Parallel()

random_suffix := acctest.RandString(t, 10)
context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-update"),
"random_suffix": acctest.RandString(t, 10),
"network_name": "tf-test-alloydb-network" + random_suffix,
"random_suffix": random_suffix,
}

acctest.VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -63,7 +64,7 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_alloydb_instance" "default" {
Expand All @@ -79,16 +80,16 @@ resource "google_compute_global_address" "private_ip_alloc" {
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = data.google_compute_network.default.id
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
data "google_compute_network" "default" {
resource "google_compute_network" "default" {
name = "%{network_name}"
}
`, context)
Expand All @@ -100,7 +101,7 @@ func TestAccAlloydbBackup_createBackupWithMandatoryFields(t *testing.T) {

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydbbackup-mandatory"),
"network_name": "tf-test-" + acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -127,12 +128,12 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
location = "us-central1"
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
data "google_project" "project" { }
data "google_compute_network" "default" {
resource "google_compute_network" "default" {
name = "%{network_name}"
}
Expand All @@ -149,7 +150,7 @@ resource "google_compute_global_address" "private_ip_alloc" {
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = data.google_compute_network.default.id
network = google_compute_network.default.id
lifecycle {
ignore_changes = [
address,
Expand All @@ -163,7 +164,7 @@ resource "google_compute_global_address" "private_ip_alloc" {
}
resource "google_service_networking_connection" "vpc_connection" {
network = data.google_compute_network.default.id
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
Expand All @@ -174,7 +175,7 @@ func TestAccAlloydbBackup_usingCMEK(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "alloydb-backup-cmek"),
"network_name": "tf-test-" + acctest.RandString(t, 10),
"random_suffix": acctest.RandString(t, 10),
"key_name": "tf-test-key-" + acctest.RandString(t, 10),
}
Expand Down Expand Up @@ -217,7 +218,7 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_alloydb_instance" "default" {
Expand All @@ -233,16 +234,16 @@ resource "google_compute_global_address" "private_ip_alloc" {
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = data.google_compute_network.default.id
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = data.google_compute_network.default.id
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
data "google_compute_network" "default" {
resource "google_compute_network" "default" {
name = "%{network_name}"
}
data "google_project" "project" {}
Expand Down
Loading

0 comments on commit dc519fb

Please sign in to comment.