From ecbf4d8edcaeb5d8a169f7c2b169d1f8d14bb1c5 Mon Sep 17 00:00:00 2001 From: Ryan Oaks Date: Tue, 28 Feb 2023 14:25:55 -0500 Subject: [PATCH 1/6] Update BootstrapProject to support use across multiple projects/environments --- .../terraform/tests/resource_container_cluster_test.go.erb | 2 +- mmv1/third_party/terraform/utils/bootstrap_utils_test.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/tests/resource_container_cluster_test.go.erb b/mmv1/third_party/terraform/tests/resource_container_cluster_test.go.erb index 560c34bf20a2..46023097e987 100644 --- a/mmv1/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -4447,7 +4447,7 @@ func TestAccContainerCluster_failedCreation(t *testing.T) { clusterName := fmt.Sprintf("tf-test-cluster-%s", RandString(t, 10)) - project := BootstrapProject(t, "tf-fail-cluster-test", GetTestBillingAccountFromEnv(t), []string{"container.googleapis.com"}) + project := BootstrapProject(t, "tf-fail-cluster-", GetTestBillingAccountFromEnv(t), []string{"container.googleapis.com"}) removeContainerServiceAgentRoleFromContainerEngineRobot(t, project) VcrTest(t, resource.TestCase{ diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index bcb464bb4d36..67204c2affb7 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -418,12 +418,17 @@ func removeContainerServiceAgentRoleFromContainerEngineRobot(t *testing.T, proje } } -func BootstrapProject(t *testing.T, projectID, billingAccount string, services []string) *cloudresourcemanager.Project { +// BootstrapProject will create or get a project named "" +// that will persist across test runs. The reason for the naming is to isolate +// bootstrapped projects by test environment. +func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, services []string) *cloudresourcemanager.Project { config := BootstrapConfig(t) if config == nil { return nil } + projectID := fmt.Printf("%s%s", projectIDPrefix, getTestProjectFromEnv(t)) + crmClient := config.NewResourceManagerClient(config.UserAgent) project, err := crmClient.Projects.Get(projectID).Do() From 123e8ff0788e65296464f14bf18c4d6400cc9ac9 Mon Sep 17 00:00:00 2001 From: Ryan Oaks Date: Tue, 28 Feb 2023 15:20:16 -0500 Subject: [PATCH 2/6] Fix typo --- mmv1/third_party/terraform/utils/bootstrap_utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index 67204c2affb7..76c1d07bc0e4 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -427,7 +427,7 @@ func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, serv return nil } - projectID := fmt.Printf("%s%s", projectIDPrefix, getTestProjectFromEnv(t)) + projectID := fmt.Sprintf("%s%s", projectIDPrefix, getTestProjectFromEnv(t)) crmClient := config.NewResourceManagerClient(config.UserAgent) From c8004514cb6fc32e51ee290b1c491fbb36583c58 Mon Sep 17 00:00:00 2001 From: Ryan Oaks Date: Tue, 28 Feb 2023 16:30:20 -0500 Subject: [PATCH 3/6] Fix arguments for getTestProjectFromEnv --- mmv1/third_party/terraform/utils/bootstrap_utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index 76c1d07bc0e4..e7cad1ed3df0 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -427,7 +427,7 @@ func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, serv return nil } - projectID := fmt.Sprintf("%s%s", projectIDPrefix, getTestProjectFromEnv(t)) + projectID := fmt.Sprintf("%s%s", projectIDPrefix, getTestProjectFromEnv()) crmClient := config.NewResourceManagerClient(config.UserAgent) From 73009657d083ffb0f3a2d89a15d6e53d700be7a0 Mon Sep 17 00:00:00 2001 From: Ryan Oaks Date: Thu, 2 Mar 2023 16:00:53 -0500 Subject: [PATCH 4/6] Fix project naming strategy for BootstrapProject to produce valid names in all envs --- .../terraform/utils/bootstrap_utils_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index e7cad1ed3df0..9ecca5f44ab7 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -418,16 +418,20 @@ func removeContainerServiceAgentRoleFromContainerEngineRobot(t *testing.T, proje } } -// BootstrapProject will create or get a project named "" -// that will persist across test runs. The reason for the naming is to isolate -// bootstrapped projects by test environment. +// BootstrapProject will create or get a project named +// "" that will persist across test runs, +// where projectIDSuffix is based off of getTestProjectFromEnv(). The reason +// for the naming is to isolate bootstrapped projects by test environment. +// Given the existing projects being used by our team, the prefix provided to +// this function can be no longer than 18 characters. func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, services []string) *cloudresourcemanager.Project { config := BootstrapConfig(t) if config == nil { return nil } - projectID := fmt.Sprintf("%s%s", projectIDPrefix, getTestProjectFromEnv()) + projectIDSuffix = strings.Replace(getTestProjectFromEnv(), "ci-test-project-", "", 1) + projectID := projectIDPrefix + projectIDSuffix crmClient := config.NewResourceManagerClient(config.UserAgent) From 4e85468fdb8cc2904b2d1c106112edfdf3359ec8 Mon Sep 17 00:00:00 2001 From: Ryan Oaks Date: Fri, 3 Mar 2023 09:57:30 -0500 Subject: [PATCH 5/6] Fix typo --- mmv1/third_party/terraform/utils/bootstrap_utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index 9ecca5f44ab7..e47d1d65d942 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -430,7 +430,7 @@ func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, serv return nil } - projectIDSuffix = strings.Replace(getTestProjectFromEnv(), "ci-test-project-", "", 1) + projectIDSuffix := strings.Replace(getTestProjectFromEnv(), "ci-test-project-", "", 1) projectID := projectIDPrefix + projectIDSuffix crmClient := config.NewResourceManagerClient(config.UserAgent) From 5f189da3f6ff9e0e345ebcc2d42dcb6ac7af392f Mon Sep 17 00:00:00 2001 From: Ryan Oaks Date: Mon, 6 Mar 2023 19:25:02 -0500 Subject: [PATCH 6/6] Fix function name after rebase --- mmv1/third_party/terraform/utils/bootstrap_utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go index e47d1d65d942..b1b0700dc8c6 100644 --- a/mmv1/third_party/terraform/utils/bootstrap_utils_test.go +++ b/mmv1/third_party/terraform/utils/bootstrap_utils_test.go @@ -430,7 +430,7 @@ func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, serv return nil } - projectIDSuffix := strings.Replace(getTestProjectFromEnv(), "ci-test-project-", "", 1) + projectIDSuffix := strings.Replace(GetTestProjectFromEnv(), "ci-test-project-", "", 1) projectID := projectIDPrefix + projectIDSuffix crmClient := config.NewResourceManagerClient(config.UserAgent)