diff --git a/auth0/resource_auth0_log_stream.go b/auth0/resource_auth0_log_stream.go index 020b45723..9099dfaf2 100644 --- a/auth0/resource_auth0_log_stream.go +++ b/auth0/resource_auth0_log_stream.go @@ -51,6 +51,18 @@ func newLogStream() *schema.Resource { }, false), Description: "Status of the LogStream", }, + "filters": { + Type: schema.TypeList, + Optional: true, + Description: "Only logs events matching these filters will be delivered by the stream." + + " If omitted or empty, all events will be delivered.", + Elem: &schema.Schema{ + Type: schema.TypeMap, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, "sink": { Type: schema.TypeList, MaxItems: 1, @@ -186,7 +198,7 @@ func newLogStream() *schema.Resource { } func createLogStream(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - logStream := buildLogStream(d) + logStream := expandLogStream(d) api := m.(*management.Management) if err := api.LogStream.Create(logStream); err != nil { @@ -225,6 +237,7 @@ func readLogStream(ctx context.Context, d *schema.ResourceData, m interface{}) d d.Set("name", logStream.Name), d.Set("status", logStream.Status), d.Set("type", logStream.Type), + d.Set("filters", logStream.Filters), d.Set("sink", flattenLogStreamSink(logStream.Sink)), ) @@ -232,7 +245,7 @@ func readLogStream(ctx context.Context, d *schema.ResourceData, m interface{}) d } func updateLogStream(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - logStream := buildLogStream(d) + logStream := expandLogStream(d) api := m.(*management.Management) if err := api.LogStream.Update(d.Id(), logStream); err != nil { return diag.FromErr(err) @@ -325,24 +338,24 @@ func flattenLogStreamSinkSumo(o *management.LogStreamSinkSumo) interface{} { } } -func buildLogStream(d ResourceData) *management.LogStream { +func expandLogStream(d ResourceData) *management.LogStream { logStream := &management.LogStream{ - Name: String(d, "name"), - Type: String(d, "type", IsNewResource()), - Status: String(d, "status", Not(IsNewResource())), + Name: String(d, "name"), + Type: String(d, "type", IsNewResource()), + Status: String(d, "status", Not(IsNewResource())), + Filters: List(d, "filters").List(), } streamType := d.Get("type").(string) - List(d, "sink").Elem(func(d ResourceData) { switch streamType { case management.LogStreamTypeAmazonEventBridge: - // LogStreamTypeAmazonEventBridge cannot be updated + // LogStreamTypeAmazonEventBridge cannot be updated. if d.IsNewResource() { logStream.Sink = expandLogStreamSinkAmazonEventBridge(d) } case management.LogStreamTypeAzureEventGrid: - // LogStreamTypeAzureEventGrid cannot be updated + // LogStreamTypeAzureEventGrid cannot be updated. if d.IsNewResource() { logStream.Sink = expandLogStreamSinkAzureEventGrid(d) } diff --git a/auth0/resource_auth0_log_stream_test.go b/auth0/resource_auth0_log_stream_test.go index bb3fb24a3..a4d279904 100644 --- a/auth0/resource_auth0_log_stream_test.go +++ b/auth0/resource_auth0_log_stream_test.go @@ -460,6 +460,20 @@ func TestAccLogStreamSumo(t *testing.T) { Check: resource.ComposeTestCheckFunc( random.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "name", "Acceptance-Test-LogStream-sumo-{{.random}}", rand), resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "type", "sumo"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "filters.#", "0"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "sink.0.sumo_source_address", "prod.sumo.com"), + ), + }, + { + Config: random.Template(logStreamSumoConfigUpdateWithFilters, rand), + Check: resource.ComposeTestCheckFunc( + random.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "name", "Acceptance-Test-LogStream-sumo-{{.random}}", rand), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "type", "sumo"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "filters.#", "2"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "filters.0.type", "category"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "filters.0.name", "auth.login.fail"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "filters.1.type", "category"), + resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "filters.1.name", "auth.signup.fail"), resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "sink.0.sumo_source_address", "prod.sumo.com"), ), }, @@ -485,3 +499,22 @@ resource "auth0_log_stream" "my_log_stream" { } } ` +const logStreamSumoConfigUpdateWithFilters = ` +resource "auth0_log_stream" "my_log_stream" { + name = "Acceptance-Test-LogStream-sumo-{{.random}}" + type = "sumo" + filters = [ + { + type = "category" + name = "auth.login.fail" + }, + { + type = "category" + name = "auth.signup.fail" + } + ] + sink { + sumo_source_address = "prod.sumo.com" + } +} +` diff --git a/docs/resources/log_stream.md b/docs/resources/log_stream.md index cc19549ea..82e319828 100644 --- a/docs/resources/log_stream.md +++ b/docs/resources/log_stream.md @@ -16,6 +16,16 @@ resource "auth0_log_stream" "example" { name = "AWS Eventbridge" type = "eventbridge" status = "active" + filters = [ + { + type = "category" + name = "auth.login.fail" + }, + { + type = "category" + name = "auth.signup.fail" + } + ] sink { aws_account_id = "my_account_id" aws_region = "us-east-2" @@ -29,6 +39,7 @@ The following arguments are supported: - `name` - (Required) Name of the log stream - `type` - (Required) The type of log stream. Options are "eventbridge", "eventgrid", "http", "datadog", "splunk", "sumo" +- `filters` - (Optional) Only logs events matching these filters will be delivered by the stream. - `status` - (Optional, Computed) The current status of the log stream. Options are "active", "paused", "suspended" - `sink` - (Optional) List(Resource) The sink configuration for the log stream. For details, see [Sink Configuration](#sink-configuration). diff --git a/example/log_stream/main.tf b/example/log_stream/main.tf index 865b10880..e186591fe 100644 --- a/example/log_stream/main.tf +++ b/example/log_stream/main.tf @@ -3,6 +3,16 @@ provider "auth0" {} resource "auth0_log_stream" "example_http" { name = "HTTP log stream" type = "http" + filters = [ + { + type = "category" + name = "auth.login.fail" + }, + { + type = "category" + name = "auth.signup.fail" + } + ] sink { http_endpoint = "https://example.com/logs" http_content_type = "application/json" @@ -10,8 +20,8 @@ resource "auth0_log_stream" "example_http" { http_authorization = "AKIAXXXXXXXXXXXXXXXX" http_custom_headers = [ { - header = "foo" - value = "bar" + header = "foo" + value = "bar" } ] } diff --git a/go.mod b/go.mod index ad32fd378..1db9d600f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,8 @@ module github.com/auth0/terraform-provider-auth0 go 1.18 require ( - github.com/auth0/go-auth0 v0.6.1 + github.com/auth0/go-auth0 v0.6.2 + github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0 ) @@ -20,7 +21,6 @@ require ( github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect github.com/hashicorp/go-hclog v1.2.0 // indirect github.com/hashicorp/go-plugin v1.4.3 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect diff --git a/go.sum b/go.sum index 9c5c0d168..71e0dfed1 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJE github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/auth0/go-auth0 v0.6.1 h1:D6WSxLQyr1+Ozn8qW0KJAKVcy1j7ZxbRoWdZQr0qT8s= -github.com/auth0/go-auth0 v0.6.1/go.mod h1:9rEJrEWFALKlt1VVCx1zToCG6+uddn4MLEgtKSRhlEU= +github.com/auth0/go-auth0 v0.6.2 h1:vnP0tdDqNDXnyRBM4Sxf4urQaKPOSV6BD8EtyhXIjhU= +github.com/auth0/go-auth0 v0.6.2/go.mod h1:9rEJrEWFALKlt1VVCx1zToCG6+uddn4MLEgtKSRhlEU= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48= github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=