Skip to content
Open
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
2 changes: 2 additions & 0 deletions examples/resources/sentry_project/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ resource "sentry_project" "default" {
# mark all functions following a prefix in-app
stack.function:mylibrary_* +app
EOT

highlight_tags = ["release", "environment"]
}
8 changes: 8 additions & 0 deletions internal/apiclient/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ paths:
type: string
verifySSL:
type: boolean
highlightTags:
type: array
items:
type: string
responses:
"200":
description: OK
Expand Down Expand Up @@ -1269,6 +1273,10 @@ components:
nullable: true
verifySSL:
type: boolean
highlightTags:
type: array
items:
type: string
ProjectKey:
type: object
required:
Expand Down
2 changes: 2 additions & 0 deletions internal/apiclient/apiclient.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions internal/provider/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/jianyuan/go-utils/sliceutils"

"github.com/jianyuan/terraform-provider-sentry/internal/apiclient"
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
"github.com/jianyuan/terraform-provider-sentry/internal/sentryclient"
Expand Down Expand Up @@ -147,6 +148,7 @@ type ProjectResourceModel struct {
FingerprintingRules sentrytypes.TrimmedString `tfsdk:"fingerprinting_rules"`
GroupingEnhancements sentrytypes.TrimmedString `tfsdk:"grouping_enhancements"`
ClientSecurity types.Object `tfsdk:"client_security"`
HighlightTags types.Set `tfsdk:"highlight_tags"`
}

func (m *ProjectResourceModel) Fill(ctx context.Context, project apiclient.Project) (diags diag.Diagnostics) {
Expand Down Expand Up @@ -184,6 +186,14 @@ func (m *ProjectResourceModel) Fill(ctx context.Context, project apiclient.Proje
diags.Append(clientSecurity.Fill(ctx, project)...)
m.ClientSecurity = tfutils.MergeDiagnostics(types.ObjectValueFrom(ctx, clientSecurity.AttributeTypes(), clientSecurity))(&diags)

if project.HighlightTags != nil {
m.HighlightTags = types.SetValueMust(types.StringType, sliceutils.Map(func(v string) attr.Value {
return types.StringValue(v)
}, *project.HighlightTags))
} else {
m.HighlightTags = types.SetNull(types.StringType)
}

return
}

Expand Down Expand Up @@ -407,6 +417,15 @@ func (r *ProjectResource) Schema(ctx context.Context, req resource.SchemaRequest
objectplanmodifier.UseStateForUnknown(),
},
},
"highlight_tags": schema.SetAttribute{
MarkdownDescription: "A list of strings with tag keys to highlight on this project's issues. E.g. ['release', 'environment']",
ElementType: types.StringType,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
},
},
}
}
Expand Down Expand Up @@ -774,6 +793,15 @@ func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest
}
}

if !plan.HighlightTags.Equal(state.HighlightTags) {
var highlightTags []string
resp.Diagnostics.Append(plan.HighlightTags.ElementsAs(ctx, &highlightTags, false)...)
if resp.Diagnostics.HasError() {
return
}
updateBody.HighlightTags = &highlightTags
}

httpRespUpdate, err := r.apiClient.UpdateOrganizationProjectWithResponse(
ctx,
plan.Organization.ValueString(),
Expand Down
37 changes: 37 additions & 0 deletions internal/provider/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/jianyuan/go-utils/must"
"github.com/jianyuan/go-utils/ptr"
"github.com/jianyuan/go-utils/sliceutils"

"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
"github.com/jianyuan/terraform-provider-sentry/internal/apiclient"
)
Expand Down Expand Up @@ -122,6 +123,22 @@ func TestAccProjectResource_basic(t *testing.T) {
return fmt.Errorf("unexpected verify tls ssl %v", project.VerifySSL)
}

if data.HighlightTags != nil {
if project.HighlightTags == nil {
return fmt.Errorf("highlight tags is nil")
}

if len(*project.HighlightTags) != len(*data.HighlightTags) {
return fmt.Errorf("unexpected highlight tags %v", *project.HighlightTags)
}

for _, tag := range *data.HighlightTags {
if !slices.Contains(*project.HighlightTags, tag) {
return fmt.Errorf("highlight tag %v not found", tag)
}
}
}

return nil
}
}
Expand Down Expand Up @@ -159,6 +176,14 @@ func TestAccProjectResource_basic(t *testing.T) {
"security_token_header": knownvalue.StringExact(ptr.Value(data.SecurityTokenHeader)),
"verify_tls_ssl": knownvalue.Bool(ptr.Value(data.VerifyTlsSsl)),
})),
func() statecheck.StateCheck {
if data.HighlightTags == nil {
return statecheck.ExpectKnownValue(rn, tfjsonpath.New("highlight_tags"), knownvalue.Null())
}
return statecheck.ExpectKnownValue(rn, tfjsonpath.New("highlight_tags"), knownvalue.SetExact(sliceutils.Map(func(v string) knownvalue.Check {
return knownvalue.StringExact(v)
}, *data.HighlightTags)))
}(),
}
}

Expand Down Expand Up @@ -233,6 +258,7 @@ func TestAccProjectResource_basic(t *testing.T) {
Platform: "python",
AllowedDomains: ptr.Ptr([]string{"jianyuan.io", "*.jianyuan.io"}),
SecurityTokenHeader: ptr.Ptr("x-my-security-token"),
HighlightTags: ptr.Ptr([]string{"release", "environment"}),
}),
Check: testAccCheckProject(rn, checkProperties(testAccProjectResourceConfig_teamsData{
AllTeamNames: []string{teamName1, teamName2, teamName3},
Expand All @@ -243,6 +269,7 @@ func TestAccProjectResource_basic(t *testing.T) {
ScrapeJavascript: ptr.Ptr(false),
SecurityTokenHeader: ptr.Ptr("x-my-security-token"),
VerifyTlsSsl: ptr.Ptr(true),
HighlightTags: ptr.Ptr([]string{"release", "environment"}),
})),
ConfigStateChecks: configStateChecks(testAccProjectResourceConfig_teamsData{
AllTeamNames: []string{teamName1, teamName2, teamName3},
Expand All @@ -253,6 +280,7 @@ func TestAccProjectResource_basic(t *testing.T) {
ScrapeJavascript: ptr.Ptr(false),
SecurityTokenHeader: ptr.Ptr("x-my-security-token"),
VerifyTlsSsl: ptr.Ptr(true),
HighlightTags: ptr.Ptr([]string{"release", "environment"}),
}),
},
// Remove all optional attributes
Expand Down Expand Up @@ -839,6 +867,14 @@ resource "sentry_project" "test" {
verify_tls_ssl = {{ .VerifyTlsSsl }}
{{ end }}
}

{{ if ne .HighlightTags nil }}
highlight_tags = [
{{ range $i, $tag := .HighlightTags }}
"{{ $tag }}",
{{ end }}
]
{{ end }}
}
`))

Expand All @@ -852,6 +888,7 @@ type testAccProjectResourceConfig_teamsData struct {
SecurityToken *string
SecurityTokenHeader *string
VerifyTlsSsl *bool
HighlightTags *[]string
}

func testAccProjectResourceConfig_teams(data testAccProjectResourceConfig_teamsData) string {
Expand Down
Loading