Skip to content

Commit

Permalink
Fix small issue with log stream filters
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Oct 7, 2022
1 parent f8e1fd6 commit 1592393
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 57 deletions.
23 changes: 10 additions & 13 deletions internal/provider/resource_auth0_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ func createLogStream(ctx context.Context, d *schema.ResourceData, m interface{})

d.SetId(logStream.GetID())

// The Management API only allows updating a log stream's status. Therefore,
// if the status field was present in the configuration, we perform an
// additional operation to modify it.
status := String(d, "status")
if status != nil && *status != logStream.GetStatus() {
if err := api.LogStream.Update(logStream.GetID(), &management.LogStream{Status: status}); err != nil {
// The Management API only allows updating a log stream's status.
// Therefore, if the status field was present in the configuration,
// we perform an additional operation to modify it.
status := d.Get("status").(string)
if status != "" && status != logStream.GetStatus() {
if err := api.LogStream.Update(logStream.GetID(), &management.LogStream{Status: &status}); err != nil {
return diag.FromErr(err)
}
}
Expand Down Expand Up @@ -369,12 +369,11 @@ func flattenLogStreamSinkSumo(o *management.LogStreamSinkSumo) interface{} {
func expandLogStream(d *schema.ResourceData) *management.LogStream {
config := d.GetRawConfig()

logStreamType := value.String(config.GetAttr("type"))

logStream := &management.LogStream{
Name: value.String(config.GetAttr("name")),
}

logStreamType := value.String(config.GetAttr("type"))
if d.IsNewResource() {
logStream.Type = logStreamType
}
Expand All @@ -385,16 +384,14 @@ func expandLogStream(d *schema.ResourceData) *management.LogStream {

filtersConfig := config.GetAttr("filters")
if !filtersConfig.IsNull() {
var filters []map[string]string
filters := make([]map[string]string, 0)

filtersConfig.ForEachElement(func(_ cty.Value, filter cty.Value) (stop bool) {
filters = append(filters, *value.MapOfStrings(filter))
return true
return stop
})

if len(filters) > 0 {
logStream.Filters = &filters
}
logStream.Filters = &filters
}

config.GetAttr("sink").ForEachElement(func(_ cty.Value, sink cty.Value) (stop bool) {
Expand Down
32 changes: 26 additions & 6 deletions internal/provider/resource_auth0_log_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/auth0/terraform-provider-auth0/internal/recorder"
"github.com/auth0/terraform-provider-auth0/internal/template"
Expand Down Expand Up @@ -58,10 +57,6 @@ func TestAccLogStreamHTTP(t *testing.T) {
{
Config: template.ParseTestName(testAccLogStreamHTTPConfig, t.Name()),
Check: resource.ComposeTestCheckFunc(
func(state *terraform.State) error {
log.Printf("%+v", state)
return nil
},
resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "name", fmt.Sprintf("Acceptance-Test-LogStream-http-%s", t.Name())),
resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "type", "http"),
resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "status", "paused"),
Expand Down Expand Up @@ -542,6 +537,15 @@ func TestAccLogStreamSumo(t *testing.T) {
resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "sink.0.sumo_source_address", "prod.sumo.com"),
),
},
{
Config: template.ParseTestName(logStreamSumoConfigUpdateWithEmptyFilters, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_log_stream.my_log_stream", "name", fmt.Sprintf("Acceptance-Test-LogStream-sumo-%s", t.Name())),
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"),
),
},
},
})
}
Expand All @@ -564,10 +568,12 @@ resource "auth0_log_stream" "my_log_stream" {
}
}
`

const logStreamSumoConfigUpdateWithFilters = `
resource "auth0_log_stream" "my_log_stream" {
name = "Acceptance-Test-LogStream-sumo-{{.testName}}"
type = "sumo"
filters = [
{
type = "category"
Expand All @@ -578,8 +584,22 @@ resource "auth0_log_stream" "my_log_stream" {
name = "auth.signup.fail"
}
]
sink {
sumo_source_address = "prod.sumo.com"
sumo_source_address = "prod.sumo.com"
}
}
`

const logStreamSumoConfigUpdateWithEmptyFilters = `
resource "auth0_log_stream" "my_log_stream" {
name = "Acceptance-Test-LogStream-sumo-{{.testName}}"
type = "sumo"
filters = [ ]
sink {
sumo_source_address = "prod.sumo.com"
}
}
`
Loading

0 comments on commit 1592393

Please sign in to comment.