Skip to content

Commit

Permalink
Made TestAccLoggingProjectSink_default use a separate project (#10386) (
Browse files Browse the repository at this point in the history
#17792)

[upstream:7f5098d08cb123b95bffe14632e1300b1b9a02a4]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Apr 8, 2024
1 parent 30f4fbe commit a9a1b1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/10386.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
33 changes: 27 additions & 6 deletions google/services/logging/resource_logging_project_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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",
Expand All @@ -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)

Expand All @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a9a1b1d

Please sign in to comment.