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

[DXCDT-104] Add filters to log_stream resource #133

Merged
merged 2 commits into from
Apr 8, 2022
Merged
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
31 changes: 22 additions & 9 deletions auth0/resource_auth0_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -225,14 +237,15 @@ 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)),
)

return diag.FromErr(result.ErrorOrNil())
}

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)
Expand Down Expand Up @@ -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)
}
Expand Down
33 changes: 33 additions & 0 deletions auth0/resource_auth0_log_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand All @@ -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"
}
}
`
11 changes: 11 additions & 0 deletions docs/resources/log_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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).

Expand Down
14 changes: 12 additions & 2 deletions example/log_stream/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ 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"
http_content_format = "JSONOBJECT"
http_authorization = "AKIAXXXXXXXXXXXXXXXX"
http_custom_headers = [
{
header = "foo"
value = "bar"
header = "foo"
value = "bar"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down