Skip to content

Commit

Permalink
Revert tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 committed Sep 16, 2023
1 parent b29c442 commit fa4a1af
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 506 deletions.
2 changes: 0 additions & 2 deletions mmv1/products/cloudbuild/BitbucketServerConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ examples:
config_id: 'bbs-config'
network_name: 'vpc-network'
global_address_name: 'private-ip-alloc'
test_vars_overrides:
network_name: 'acctest.BootstrapSharedTestNetwork(t, "peered-network")'
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/cloudbuild_bitbucketserver_config.go.erb
post_create: templates/terraform/post_create/cloudbuild_bitbucketserver_config.go.erb
Expand Down
2 changes: 0 additions & 2 deletions mmv1/products/vertexai/IndexEndpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ examples:
vars:
address_name: "address-name"
network_name: "network-name"
test_vars_overrides:
network_name: 'acctest.BootstrapSharedTestNetwork(t, "vertex-ai-index-endpoint")'
- !ruby/object:Provider::Terraform::Examples
name: "vertex_ai_index_endpoint_with_public_endpoint"
primary_resource_id: "index_endpoint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ resource "google_project_service" "servicenetworking" {
service = "servicenetworking.googleapis.com"
disable_on_destroy = false
}
data "google_compute_network" "vpc_network" {

resource "google_compute_network" "vpc_network" {
name = "<%= ctx[:vars]['network_name'] %>"
depends_on = [google_project_service.servicenetworking]
}
Expand All @@ -15,11 +15,11 @@ resource "google_compute_global_address" "private_ip_alloc" {
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.vpc_network.id
network = google_compute_network.vpc_network.id
}

resource "google_service_networking_connection" "default" {
network = data.google_compute_network.vpc_network.id
network = google_compute_network.vpc_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
depends_on = [google_project_service.servicenetworking]
Expand All @@ -36,7 +36,7 @@ resource "google_cloudbuild_bitbucket_server_config" "<%= ctx[:primary_resource_
}
username = "test"
api_key = "<api-key>"
peered_network = replace(data.google_compute_network.vpc_network.id, data.google_project.project.name, data.google_project.project.number)
peered_network = replace(google_compute_network.vpc_network.id, data.google_project.project.name, data.google_project.project.number)
ssl_ca = "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n"
depends_on = [google_service_networking_connection.default]
}
6 changes: 3 additions & 3 deletions mmv1/templates/terraform/examples/tpu_node_full.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "google_tpu_node" "<%= ctx[:primary_resource_id] %>" {
}
}

data "google_compute_network" "network" {
resource "google_compute_network" "network" {
name = "default"
}

Expand All @@ -43,11 +43,11 @@ resource "google_compute_global_address" "service_range" {
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.network.id
network = google_compute_network.network.id
}

resource "google_service_networking_connection" "private_service_connection" {
network = data.google_compute_network.network.id
network = google_compute_network.network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.service_range.name]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "google_vertex_ai_endpoint" "<%= ctx[:primary_resource_id] %>" {
labels = {
label-one = "value-one"
}
network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}"
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.vertex_network.name}"
encryption_spec {
kms_key_name = "<%= ctx[:vars]['kms_key_name'] %>"
}
Expand All @@ -17,7 +17,7 @@ resource "google_vertex_ai_endpoint" "<%= ctx[:primary_resource_id] %>" {
}

resource "google_service_networking_connection" "vertex_vpc_connection" {
network = data.google_compute_network.vertex_network.id
network = google_compute_network.vertex_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.vertex_range.name]
}
Expand All @@ -27,10 +27,10 @@ resource "google_compute_global_address" "vertex_range" {
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 24
network = data.google_compute_network.vertex_network.id
network = google_compute_network.vertex_network.id
}

data "google_compute_network" "vertex_network" {
resource "google_compute_network" "vertex_network" {
name = "<%= ctx[:vars]['network_name'] %>"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ resource "google_vertex_ai_index_endpoint" "<%= ctx[:primary_resource_id] %>" {
labels = {
label-one = "value-one"
}
network = "projects/${data.google_project.project.number}/global/networks/${data.google_compute_network.vertex_network.name}"
network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.vertex_network.name}"
depends_on = [
google_service_networking_connection.vertex_vpc_connection
]
}

resource "google_service_networking_connection" "vertex_vpc_connection" {
network = data.google_compute_network.vertex_network.id
network = google_compute_network.vertex_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.vertex_range.name]
}
Expand All @@ -22,10 +22,10 @@ resource "google_compute_global_address" "vertex_range" {
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 24
network = data.google_compute_network.vertex_network.id
network = google_compute_network.vertex_network.id
}

data "google_compute_network" "vertex_network" {
resource "google_compute_network" "vertex_network" {
name = "<%= ctx[:vars]['network_name'] %>"
}

Expand Down
11 changes: 7 additions & 4 deletions mmv1/third_party/terraform/acctest/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"testing"
"time"

tpgservicenetworking "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/servicenetworking"
"github.com/hashicorp/terraform-provider-google/google/envvar"
tpgcompute "github.com/hashicorp/terraform-provider-google/google/services/compute"
"github.com/hashicorp/terraform-provider-google/google/services/privateca"
"github.com/hashicorp/terraform-provider-google/google/services/resourcemanager"
tpgservicenetworking "github.com/hashicorp/terraform-provider-google/google/services/servicenetworking"
"github.com/hashicorp/terraform-provider-google/google/services/sql"
"github.com/hashicorp/terraform-provider-google/google/tpgiamresource"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
Expand Down Expand Up @@ -410,16 +410,17 @@ func BootstrapSharedTestGlobalAddress(t *testing.T, testId, networkId string) st
return address.Name
}

func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string) {
func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string) string {
parentService := "services/servicenetworking.googleapis.com"
project := envvar.GetTestProjectFromEnv()

config := BootstrapConfig(t)
if config == nil {
return
return ""
}

networkId := fmt.Sprintf("projects/%v/global/networks/%v", project, BootstrapSharedTestNetwork(t, testId))
networkName := BootstrapSharedTestNetwork(t, testId)
networkId := fmt.Sprintf("projects/%v/global/networks/%v", project, networkName)
globalAddressName := BootstrapSharedTestGlobalAddress(t, testId, networkId)

readCall := config.NewServiceNetworkingClient(config.UserAgent).Services.Connections.List(parentService).Network(networkId)
Expand Down Expand Up @@ -463,6 +464,8 @@ func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string) {
}

log.Printf("[DEBUG] Getting shared test service networking connection")

return networkName
}

var SharedServicePerimeterProjectPrefix = "tf-bootstrap-sp-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestAccAlloydbBackup_update(t *testing.T) {

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

Expand Down Expand Up @@ -62,32 +62,16 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = google_compute_network.default.id
network = data.google_compute_network.default.id
}
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "tf-test-alloydb-cluster%{random_suffix}"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
resource "google_compute_network" "default" {
data "google_compute_network" "default" {
name = "%{network_name}"
}
`, context)
Expand All @@ -99,7 +83,7 @@ func TestAccAlloydbBackup_createBackupWithMandatoryFields(t *testing.T) {

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

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -126,45 +110,19 @@ resource "google_alloydb_backup" "default" {
resource "google_alloydb_cluster" "default" {
location = "us-central1"
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
network = google_compute_network.default.id
network = data.google_compute_network.default.id
}
data "google_project" "project" { }
resource "google_compute_network" "default" {
data "google_compute_network" "default" {
name = "%{network_name}"
}
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "tf-test-alloydb-cluster%{random_suffix}"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
lifecycle {
ignore_changes = [
address,
creation_timestamp,
id,
network,
project,
self_link
]
}
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
`, context)
}
Expand All @@ -173,7 +131,7 @@ func TestAccAlloydbBackup_usingCMEK(t *testing.T) {
t.Parallel()

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

0 comments on commit fa4a1af

Please sign in to comment.