Skip to content

Commit

Permalink
Add description and disabled to logging sinks (#4233) (#7809)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Iverson <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Alec Iverson <[email protected]>
  • Loading branch information
modular-magician and Alec Iverson authored Nov 13, 2020
1 parent 1ace75e commit e9da53c
Show file tree
Hide file tree
Showing 10 changed files with 412 additions and 21 deletions.
10 changes: 10 additions & 0 deletions .changelog/4233.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```release-note:enhancement
logging: added `description` field to `google_logging_folder_sink` resource
logging: added `description` field to `google_logging_project_sink` resource
logging: added `description` field to `google_logging_organization_sink` resource
logging: added `description` field to `google_logging_billing_account_sink` resource
logging: added `disabled` field to `google_logging_folder_sink` resource
logging: added `disabled` field to `google_logging_project_sink` resource
logging: added `disabled` field to `google_logging_organization_sink` resource
logging: added `disabled` field to `google_logging_billing_account_sink` resource
```
80 changes: 79 additions & 1 deletion google/resource_logging_billing_account_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ 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)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingBillingAccountSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingBillingAccountSink_described(sinkName, bucketName, billingAccount),
}, {
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)

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

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

Expand Down Expand Up @@ -221,12 +267,44 @@ 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"
description = "this is a description"
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"
}
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"
}
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" {
name = "%s"
billing_account = "%s"
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"
}
Expand All @@ -244,7 +322,7 @@ resource "google_logging_billing_account_sink" "heredoc" {
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = <<EOS
logName="projects/%s/logs/compute.googleapis.com%%2Factivity_log"
logName="projects/%s/logs/compute.googleapis.com%%2Factivity_log"
AND severity>=ERROR
Expand Down
108 changes: 100 additions & 8 deletions google/resource_logging_folder_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,54 @@ 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)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingFolderSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingFolderSink_described(sinkName, bucketName, folderName, "organizations/"+org),
}, {
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)

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

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

Expand Down Expand Up @@ -308,22 +356,66 @@ 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" {
name = "%s"
folder = "${element(split("/", google_folder.my-folder.name), 1)}"
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = ""
include_children = true
name = "%s"
folder = "${element(split("/", google_folder.my-folder.name), 1)}"
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = ""
include_children = true
}
resource "google_storage_bucket" "log-bucket" {
name = "%s"
name = "%s"
}
resource "google_folder" "my-folder" {
display_name = "%s"
display_name = "%s"
parent = "%s"
}`, sinkName, bucketName, folderName, folderParent)
}
Expand Down Expand Up @@ -357,7 +449,7 @@ resource "google_logging_folder_sink" "heredoc" {
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = <<EOS
logName="projects/%s/logs/compute.googleapis.com%%2Factivity_log"
logName="projects/%s/logs/compute.googleapis.com%%2Factivity_log"
AND severity>=ERROR
Expand Down
87 changes: 85 additions & 2 deletions 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,52 @@ 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)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLoggingOrganizationSinkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccLoggingOrganizationSink_described(sinkName, bucketName, org),
}, {
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)

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

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

Expand Down Expand Up @@ -250,6 +297,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 All @@ -258,7 +341,7 @@ resource "google_logging_organization_sink" "heredoc" {
destination = "storage.googleapis.com/${google_storage_bucket.log-bucket.name}"
filter = <<EOS
logName="projects/%s/logs/compute.googleapis.com%%2Factivity_log"
logName="projects/%s/logs/compute.googleapis.com%%2Factivity_log"
AND severity>=ERROR
Expand Down
Loading

0 comments on commit e9da53c

Please sign in to comment.