From a9a1b1d43eade563c55e9eb77d0645fe17bdeaf8 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 8 Apr 2024 11:31:10 -0700 Subject: [PATCH] Made TestAccLoggingProjectSink_default use a separate project (#10386) (#17792) [upstream:7f5098d08cb123b95bffe14632e1300b1b9a02a4] Signed-off-by: Modular Magician --- .changelog/10386.txt | 3 ++ .../resource_logging_project_sink_test.go | 33 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .changelog/10386.txt diff --git a/.changelog/10386.txt b/.changelog/10386.txt new file mode 100644 index 00000000000..42b910df155 --- /dev/null +++ b/.changelog/10386.txt @@ -0,0 +1,3 @@ +```release-note:none + +``` \ No newline at end of file diff --git a/google/services/logging/resource_logging_project_sink_test.go b/google/services/logging/resource_logging_project_sink_test.go index 0bc8ed110b1..92c4f8f84d7 100644 --- a/google/services/logging/resource_logging_project_sink_test.go +++ b/google/services/logging/resource_logging_project_sink_test.go @@ -15,6 +15,9 @@ import ( func TestAccLoggingProjectSink_basic(t *testing.T) { t.Parallel() + orgId := envvar.GetTestOrgFromEnv(t) + billingAccount := envvar.GetTestBillingAccountFromEnv(t) + projectId := "tf-test" + acctest.RandString(t, 10) sinkName := "tf-test-sink-" + acctest.RandString(t, 10) bucketName := "tf-test-sink-bucket-" + acctest.RandString(t, 10) @@ -24,7 +27,7 @@ func TestAccLoggingProjectSink_basic(t *testing.T) { CheckDestroy: testAccCheckLoggingProjectSinkDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccLoggingProjectSink_basic(sinkName, envvar.GetTestProjectFromEnv(), bucketName), + Config: testAccLoggingProjectSink_basic(projectId, orgId, billingAccount, sinkName, bucketName, "false"), }, { ResourceName: "google_logging_project_sink.basic", @@ -38,6 +41,9 @@ func TestAccLoggingProjectSink_basic(t *testing.T) { func TestAccLoggingProjectSink_default(t *testing.T) { t.Parallel() + orgId := envvar.GetTestOrgFromEnv(t) + billingAccount := envvar.GetTestBillingAccountFromEnv(t) + projectId := "tf-test" + acctest.RandString(t, 10) sinkName := "_Default" bucketName := "tf-test-sink-bucket-" + acctest.RandString(t, 10) @@ -46,7 +52,8 @@ func TestAccLoggingProjectSink_default(t *testing.T) { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), Steps: []resource.TestStep{ { - Config: testAccLoggingProjectSink_basic(sinkName, envvar.GetTestProjectFromEnv(), bucketName), + // Default sink has a permadiff if any value is sent for "disabled" other than "true" + Config: testAccLoggingProjectSink_basic(projectId, orgId, billingAccount, sinkName, bucketName, "true"), }, { ResourceName: "google_logging_project_sink.basic", @@ -365,20 +372,34 @@ func testAccCheckLoggingProjectSinkDestroyProducer(t *testing.T) func(s *terrafo } } -func testAccLoggingProjectSink_basic(name, project, bucketName string) string { +func testAccLoggingProjectSink_basic(projectId, orgId, billingAccount, sinkName, bucketName, disabled string) string { return fmt.Sprintf(` +resource "google_project" "project" { + project_id = "%s" + name = "%s" + org_id = "%s" + billing_account = "%s" +} + +resource "google_project_service" "logging_service" { + project = google_project.project.project_id + service = "logging.googleapis.com" +} + resource "google_logging_project_sink" "basic" { name = "%s" - project = "%s" + disabled = %s + project = google_project_service.logging_service.project destination = "storage.googleapis.com/${google_storage_bucket.gcs-bucket.name}" - filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR" + filter = "logName=\"projects/${google_project.project.project_id}/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR" } resource "google_storage_bucket" "gcs-bucket" { name = "%s" + project = google_project.project.project_id location = "US" } -`, name, project, project, bucketName) +`, projectId, projectId, orgId, billingAccount, sinkName, disabled, bucketName) } func testAccLoggingProjectSink_described(name, project, bucketName string) string {