diff --git a/go.mod b/go.mod index 69ac0009..e9ae4dd4 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-mux v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 - github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675 + github.com/jianyuan/go-sentry/v2 v2.6.2 golang.org/x/oauth2 v0.15.0 golang.org/x/sync v0.5.0 ) diff --git a/go.sum b/go.sum index 593eea04..f7cc7da8 100644 --- a/go.sum +++ b/go.sum @@ -135,8 +135,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= -github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675 h1:H6d/M5s+lz1bQahmaSwUYCZ95uiPmw+lJYxFa2axfFo= -github.com/jianyuan/go-sentry/v2 v2.5.1-0.20231214003649-288c5a250675/go.mod h1:YN4yg9u6/b5TfsmXy8OauRu3cyvVXRe1mJY7Pe+/Dt4= +github.com/jianyuan/go-sentry/v2 v2.6.2 h1:tMcsFMjON1IvOtpW1KxZmfdRbW7IXUHY7Kwk6Rmi7oY= +github.com/jianyuan/go-sentry/v2 v2.6.2/go.mod h1:YN4yg9u6/b5TfsmXy8OauRu3cyvVXRe1mJY7Pe+/Dt4= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= diff --git a/internal/provider/resource_dashboard_test.go b/internal/provider/resource_dashboard_test.go new file mode 100644 index 00000000..21afacfe --- /dev/null +++ b/internal/provider/resource_dashboard_test.go @@ -0,0 +1,52 @@ +package provider + +import ( + "context" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/jianyuan/go-sentry/v2/sentry" + "github.com/jianyuan/terraform-provider-sentry/internal/acctest" +) + +func init() { + resource.AddTestSweepers("sentry_dashboard", &resource.Sweeper{ + Name: "sentry_dashboard", + F: func(r string) error { + ctx := context.Background() + + listParams := &sentry.ListCursorParams{} + + for { + dashboards, resp, err := acctest.SharedClient.Dashboards.List(ctx, acctest.TestOrganization, listParams) + if err != nil { + return err + } + + for _, dashboard := range dashboards { + if !strings.HasPrefix(sentry.StringValue(dashboard.Title), "tf-dashboard") { + continue + } + + log.Printf("[INFO] Destroying Dashboard %q", sentry.StringValue(dashboard.Title)) + + _, err := acctest.SharedClient.Dashboards.Delete(ctx, acctest.TestOrganization, sentry.StringValue(dashboard.ID)) + if err != nil { + log.Printf("[ERROR] Failed to destroy Dashboard %q: %s", sentry.StringValue(dashboard.Title), err) + continue + } + + log.Printf("[INFO] Dashboard %q has been destroyed.", sentry.StringValue(dashboard.Title)) + } + + if resp.Cursor == "" { + break + } + listParams.Cursor = resp.Cursor + } + + return nil + }, + }) +} diff --git a/internal/provider/resource_project_inbound_data_filter.go b/internal/provider/resource_project_inbound_data_filter.go index ab8fea99..75d5a166 100644 --- a/internal/provider/resource_project_inbound_data_filter.go +++ b/internal/provider/resource_project_inbound_data_filter.go @@ -48,7 +48,7 @@ func (m *ProjectInboundDataFilterResourceModel) Fill(organization string, projec m.Active = types.BoolValue(filter.Active.BoolVal) } else { subfilterElements := []attr.Value{} - for _, subfilter := range filter.Active.SliceVal { + for _, subfilter := range filter.Active.StringSliceVal { subfilterElements = append(subfilterElements, types.StringValue(subfilter)) } diff --git a/internal/provider/resource_project_test.go b/internal/provider/resource_project_test.go new file mode 100644 index 00000000..48c0320c --- /dev/null +++ b/internal/provider/resource_project_test.go @@ -0,0 +1,52 @@ +package provider + +import ( + "context" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/jianyuan/go-sentry/v2/sentry" + "github.com/jianyuan/terraform-provider-sentry/internal/acctest" +) + +func init() { + resource.AddTestSweepers("sentry_project", &resource.Sweeper{ + Name: "sentry_project", + F: func(r string) error { + ctx := context.Background() + + listParams := &sentry.ListCursorParams{} + + for { + projects, resp, err := acctest.SharedClient.Projects.List(ctx, listParams) + if err != nil { + return err + } + + for _, project := range projects { + if !strings.HasPrefix(project.Slug, "tf-project") { + continue + } + + log.Printf("[INFO] Destroying Project: %s", project.Slug) + + _, err := acctest.SharedClient.Projects.Delete(ctx, acctest.TestOrganization, project.Slug) + if err != nil { + log.Printf("[ERROR] Failed to destroy Project %q: %s", project.Slug, err) + continue + } + + log.Printf("[INFO] Project %q has been destroyed.", project.Slug) + } + + if resp.Cursor == "" { + break + } + listParams.Cursor = resp.Cursor + } + + return nil + }, + }) +} diff --git a/internal/provider/resource_team_test.go b/internal/provider/resource_team_test.go new file mode 100644 index 00000000..428985ba --- /dev/null +++ b/internal/provider/resource_team_test.go @@ -0,0 +1,43 @@ +package provider + +import ( + "context" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/jianyuan/go-sentry/v2/sentry" + "github.com/jianyuan/terraform-provider-sentry/internal/acctest" +) + +func init() { + resource.AddTestSweepers("sentry_team", &resource.Sweeper{ + Name: "sentry_team", + F: func(r string) error { + ctx := context.Background() + + teams, _, err := acctest.SharedClient.Teams.List(ctx, acctest.TestOrganization) + if err != nil { + return err + } + + for _, team := range teams { + if !strings.HasPrefix(sentry.StringValue(team.Slug), "tf-team") { + continue + } + + log.Printf("[INFO] Destroying Team: %s", sentry.StringValue(team.Slug)) + + _, err := acctest.SharedClient.Teams.Delete(ctx, acctest.TestOrganization, sentry.StringValue(team.Slug)) + if err != nil { + log.Printf("[ERROR] Failed to destroy Team %q: %s", sentry.StringValue(team.Slug), err) + continue + } + + log.Printf("[INFO] Team %q has been destroyed.", sentry.StringValue(team.Slug)) + } + + return nil + }, + }) +} diff --git a/sentry/resource_sentry_metric_alert.go b/sentry/resource_sentry_metric_alert.go index 1820c954..a26fbb49 100644 --- a/sentry/resource_sentry_metric_alert.go +++ b/sentry/resource_sentry_metric_alert.go @@ -353,7 +353,7 @@ func expandMetricAlertTriggerActions(actionList []interface{}) []*sentry.MetricA } if v, ok := actionMap["target_identifier"].(string); ok { if v != "" { - action.TargetIdentifier = sentry.String(v) + action.TargetIdentifier = &sentry.Int64OrString{IsString: true, StringVal: v} } } if v, ok := actionMap["input_channel_id"].(string); ok { @@ -401,7 +401,13 @@ func flattenMetricAlertTriggerActions(actions []*sentry.MetricAlertTriggerAction actionMap["id"] = action.ID actionMap["type"] = action.Type actionMap["target_type"] = action.TargetType - actionMap["target_identifier"] = action.TargetIdentifier + if action.TargetIdentifier != nil { + if action.TargetIdentifier.IsInt64 { + actionMap["target_identifier"] = action.TargetIdentifier.Int64Val + } else { + actionMap["target_identifier"] = action.TargetIdentifier.StringVal + } + } actionMap["input_channel_id"] = action.InputChannelID actionMap["integration_id"] = action.IntegrationID