Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description and disabled fields to logging sinks #7795

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions google/resource_logging_billing_account_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,64 @@ func TestAccLoggingBillingAccountSink_update(t *testing.T) {
}
}

func TestAccLoggingBillingAccountSink_described(t *testing.T) {
t.Parallel()

sinkName := "tf-test-sink-" + randString(t, 10)
bucketName := "tf-test-sink-bucket-" + randString(t, 10)
billingAccount := getTestBillingAccountFromEnv(t)

var sink logging.LogSink

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingBillingAccountSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingBillingAccountSink_described(sinkName, bucketName, billingAccount),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoggingBillingAccountSinkExists(t, "google_logging_billing_account_sink.described", &sink),
testAccCheckLoggingBillingAccountSink(&sink, "google_logging_billing_account_sink.described"),
),
}, {
ResourceName: "google_logging_billing_account_sink.described",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccLoggingBillingAccountSink_disabled(t *testing.T) {
t.Parallel()

sinkName := "tf-test-sink-" + randString(t, 10)
bucketName := "tf-test-sink-bucket-" + randString(t, 10)
billingAccount := getTestBillingAccountFromEnv(t)

var sink logging.LogSink

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingBillingAccountSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingBillingAccountSink_disabled(sinkName, bucketName, billingAccount),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoggingBillingAccountSinkExists(t, "google_logging_billing_account_sink.disabled", &sink),
testAccCheckLoggingBillingAccountSink(&sink, "google_logging_billing_account_sink.disabled"),
),
}, {
ResourceName: "google_logging_billing_account_sink.disabled",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccLoggingBillingAccountSink_updateBigquerySink(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -221,6 +279,38 @@ resource "google_storage_bucket" "log-bucket" {
`, name, billingAccount, getTestProjectFromEnv(), bucketName)
}

func testAccLoggingBillingAccountSink_described(name, bucketName, billingAccount string) string {
return fmt.Sprintf(`
resource "google_logging_billing_account_sink" "described" {
name = "%s"
billing_account = "%s"
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR"
description = "this is a description for a billing account level logging sink"
}

resource "google_storage_bucket" "log-bucket" {
name = "%s"
}
`, name, billingAccount, getTestProjectFromEnv(), bucketName)
}

func testAccLoggingBillingAccountSink_disabled(name, bucketName, billingAccount string) string {
return fmt.Sprintf(`
resource "google_logging_billing_account_sink" "disabled" {
name = "%s"
billing_account = "%s"
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR"
disabled = true
}

resource "google_storage_bucket" "log-bucket" {
name = "%s"
}
`, name, billingAccount, getTestProjectFromEnv(), bucketName)
}

func testAccLoggingBillingAccountSink_update(name, bucketName, billingAccount string) string {
return fmt.Sprintf(`
resource "google_logging_billing_account_sink" "update" {
Expand Down
104 changes: 104 additions & 0 deletions google/resource_logging_folder_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,66 @@ func TestAccLoggingFolderSink_basic(t *testing.T) {
})
}

func TestAccLoggingFolderSink_described(t *testing.T) {
t.Parallel()

org := getTestOrgFromEnv(t)
sinkName := "tf-test-sink-" + randString(t, 10)
bucketName := "tf-test-sink-bucket-" + randString(t, 10)
folderName := "tf-test-folder-" + randString(t, 10)

var sink logging.LogSink

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingFolderSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingFolderSink_described(sinkName, bucketName, folderName, "organizations/"+org),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoggingFolderSinkExists(t, "google_logging_folder_sink.described", &sink),
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.described"),
),
}, {
ResourceName: "google_logging_folder_sink.described",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccLoggingFolderSink_disabled(t *testing.T) {
t.Parallel()

org := getTestOrgFromEnv(t)
sinkName := "tf-test-sink-" + randString(t, 10)
bucketName := "tf-test-sink-bucket-" + randString(t, 10)
folderName := "tf-test-folder-" + randString(t, 10)

var sink logging.LogSink

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingFolderSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingFolderSink_disabled(sinkName, bucketName, folderName, "organizations/"+org),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoggingFolderSinkExists(t, "google_logging_folder_sink.disabled", &sink),
testAccCheckLoggingFolderSink(&sink, "google_logging_folder_sink.disabled"),
),
}, {
ResourceName: "google_logging_folder_sink.disabled",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccLoggingFolderSink_removeOptionals(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -308,6 +368,50 @@ resource "google_folder" "my-folder" {
`, sinkName, getTestProjectFromEnv(), bucketName, folderName, folderParent)
}

func testAccLoggingFolderSink_described(sinkName, bucketName, folderName, folderParent string) string {
return fmt.Sprintf(`
resource "google_logging_folder_sink" "described" {
name = "%s"
folder = element(split("/", google_folder.my-folder.name), 1)
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
description = "this is a description for a folder level logging sink"
filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR"
include_children = true
}

resource "google_storage_bucket" "log-bucket" {
name = "%s"
}

resource "google_folder" "my-folder" {
display_name = "%s"
parent = "%s"
}
`, sinkName, getTestProjectFromEnv(), bucketName, folderName, folderParent)
}

func testAccLoggingFolderSink_disabled(sinkName, bucketName, folderName, folderParent string) string {
return fmt.Sprintf(`
resource "google_logging_folder_sink" "disabled" {
name = "%s"
folder = element(split("/", google_folder.my-folder.name), 1)
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
disabled = true
filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR"
include_children = true
}

resource "google_storage_bucket" "log-bucket" {
name = "%s"
}

resource "google_folder" "my-folder" {
display_name = "%s"
parent = "%s"
}
`, sinkName, getTestProjectFromEnv(), bucketName, folderName, folderParent)
}

func testAccLoggingFolderSink_removeOptionals(sinkName, bucketName, folderName, folderParent string) string {
return fmt.Sprintf(`
resource "google_logging_folder_sink" "basic" {
Expand Down
97 changes: 96 additions & 1 deletion google/resource_logging_organization_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"
"testing"

"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"google.golang.org/api/logging/v2"
"strconv"
)

func TestAccLoggingOrganizationSink_basic(t *testing.T) {
Expand Down Expand Up @@ -84,6 +85,64 @@ func TestAccLoggingOrganizationSink_update(t *testing.T) {
}
}

func TestAccLoggingOrganizationSink_described(t *testing.T) {
t.Parallel()

org := getTestOrgFromEnv(t)
sinkName := "tf-test-sink-" + randString(t, 10)
bucketName := "tf-test-sink-bucket-" + randString(t, 10)

var sink logging.LogSink

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingOrganizationSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingOrganizationSink_described(sinkName, bucketName, org),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoggingOrganizationSinkExists(t, "google_logging_organization_sink.described", &sink),
testAccCheckLoggingOrganizationSink(&sink, "google_logging_organization_sink.described"),
),
}, {
ResourceName: "google_logging_organization_sink.described",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccLoggingOrganizationSink_disabled(t *testing.T) {
t.Parallel()

org := getTestOrgFromEnv(t)
sinkName := "tf-test-sink-" + randString(t, 10)
bucketName := "tf-test-sink-bucket-" + randString(t, 10)

var sink logging.LogSink

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingOrganizationSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingOrganizationSink_disabled(sinkName, bucketName, org),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoggingOrganizationSinkExists(t, "google_logging_organization_sink.disabled", &sink),
testAccCheckLoggingOrganizationSink(&sink, "google_logging_organization_sink.disabled"),
),
}, {
ResourceName: "google_logging_organization_sink.disabled",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccLoggingOrganizationSink_updateBigquerySink(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -250,6 +309,42 @@ resource "google_storage_bucket" "log-bucket" {
`, sinkName, orgId, getTestProjectFromEnv(), bucketName)
}

func testAccLoggingOrganizationSink_described(sinkName, bucketName, orgId string) string {
return fmt.Sprintf(`
resource "google_logging_organization_sink" "described" {
name = "%s"
project = "%s"
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR"
description = "this is a description for an organization level logging sink"

unique_writer_identity = false
}

resource "google_storage_bucket" "log-bucket" {
name = "%s"
}
`, sinkName, orgId, getTestProjectFromEnv(), bucketName)
}

func testAccLoggingOrganizationSink_disabled(sinkName, bucketName, orgId string) string {
return fmt.Sprintf(`
resource "google_logging_organization_sink" "disabled" {
name = "%s"
project = "%s"
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = "logName=\"projects/%s/logs/compute.googleapis.com%%2Factivity_log\" AND severity>=ERROR"
disabled = true

unique_writer_identity = false
}

resource "google_storage_bucket" "log-bucket" {
name = "%s"
}
`, sinkName, orgId, getTestProjectFromEnv(), bucketName)
}

func testAccLoggingOrganizationSink_heredoc(sinkName, bucketName, orgId string) string {
return fmt.Sprintf(`
resource "google_logging_organization_sink" "heredoc" {
Expand Down
Loading