diff --git a/google/resource_logging_billing_account_sink_test.go b/google/resource_logging_billing_account_sink_test.go index b4c99e4c0f8..2ee01f739cd 100644 --- a/google/resource_logging_billing_account_sink_test.go +++ b/google/resource_logging_billing_account_sink_test.go @@ -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() @@ -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" { diff --git a/google/resource_logging_folder_sink_test.go b/google/resource_logging_folder_sink_test.go index 2191a0289c5..2d85030fc9d 100644 --- a/google/resource_logging_folder_sink_test.go +++ b/google/resource_logging_folder_sink_test.go @@ -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() @@ -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" { diff --git a/google/resource_logging_organization_sink_test.go b/google/resource_logging_organization_sink_test.go index e88136959ce..e79c6a51b6f 100644 --- a/google/resource_logging_organization_sink_test.go +++ b/google/resource_logging_organization_sink_test.go @@ -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) { @@ -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() @@ -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" { diff --git a/google/resource_logging_project_sink_test.go b/google/resource_logging_project_sink_test.go index 254a3b1a897..10bad96ee6e 100644 --- a/google/resource_logging_project_sink_test.go +++ b/google/resource_logging_project_sink_test.go @@ -31,6 +31,52 @@ func TestAccLoggingProjectSink_basic(t *testing.T) { }) } +func TestAccLoggingProjectSink_described(t *testing.T) { + t.Parallel() + + 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: testAccCheckLoggingProjectSinkDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccLoggingProjectSink_described(sinkName, getTestProjectFromEnv(), bucketName), + }, + { + ResourceName: "google_logging_project_sink.described", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccLoggingProjectSink_disabled(t *testing.T) { + t.Parallel() + + 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: testAccCheckLoggingProjectSinkDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccLoggingProjectSink_disabled(sinkName, getTestProjectFromEnv(), bucketName), + }, + { + ResourceName: "google_logging_project_sink.disabled", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccLoggingProjectSink_updatePreservesUniqueWriter(t *testing.T) { t.Parallel() @@ -177,6 +223,42 @@ resource "google_storage_bucket" "log-bucket" { `, name, project, project, bucketName) } +func testAccLoggingProjectSink_described(name, project, bucketName string) string { + return fmt.Sprintf(` +resource "google_logging_project_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 a project level logging sink" + + unique_writer_identity = false +} + +resource "google_storage_bucket" "log-bucket" { + name = "%s" +} +`, name, project, project, bucketName) +} + +func testAccLoggingProjectSink_disabled(name, project, bucketName string) string { + return fmt.Sprintf(` +resource "google_logging_project_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" +} +`, name, project, project, bucketName) +} + func testAccLoggingProjectSink_uniqueWriter(name, bucketName string) string { return fmt.Sprintf(` resource "google_logging_project_sink" "unique_writer" { diff --git a/google/resource_logging_sink.go b/google/resource_logging_sink.go index 428c7bcdf6b..b977afbc3c4 100644 --- a/google/resource_logging_sink.go +++ b/google/resource_logging_sink.go @@ -30,6 +30,18 @@ func resourceLoggingSinkSchema() map[string]*schema.Schema { Description: `The filter to apply when exporting logs. Only log entries that match the filter are exported.`, }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: `A description of this sink. The maximum length of the description is 8000 characters.`, + }, + + "disabled": { + Type: schema.TypeBool, + Optional: true, + Description: `If set to True, then this sink is disabled and it does not export any log entries.`, + }, + "exclusions": { Type: schema.TypeList, Optional: true, @@ -97,6 +109,8 @@ func expandResourceLoggingSink(d *schema.ResourceData, resourceType, resourceId Name: d.Get("name").(string), Destination: d.Get("destination").(string), Filter: d.Get("filter").(string), + Description: d.Get("description").(string), + Disabled: d.Get("disabled").(bool), Exclusions: expandLoggingSinkExclusions(d.Get("exclusions")), BigqueryOptions: expandLoggingSinkBigqueryOptions(d.Get("bigquery_options")), } @@ -113,6 +127,12 @@ func flattenResourceLoggingSink(d *schema.ResourceData, sink *logging.LogSink) e if err := d.Set("filter", sink.Filter); err != nil { return fmt.Errorf("Error setting filter: %s", err) } + if err := d.Set("description", sink.Description); err != nil { + return fmt.Errorf("Error setting description: %s", err) + } + if err := d.Set("disabled", sink.Disabled); err != nil { + return fmt.Errorf("Error setting disabled: %s", err) + } if err := d.Set("writer_identity", sink.WriterIdentity); err != nil { return fmt.Errorf("Error setting writer_identity: %s", err) } @@ -142,6 +162,12 @@ func expandResourceLoggingSinkForUpdate(d *schema.ResourceData) (sink *logging.L if d.HasChange("filter") { updateFields = append(updateFields, "filter") } + if d.HasChange("description") { + updateFields = append(updateFields, "description") + } + if d.HasChange("disabled") { + updateFields = append(updateFields, "disabled") + } if d.HasChange("exclusions") { sink.Exclusions = expandLoggingSinkExclusions(d.Get("exclusions")) updateFields = append(updateFields, "exclusions")