Skip to content

Commit b5da4e8

Browse files
committed
fix: do not remove default key on project update
1 parent 57a2a4f commit b5da4e8

File tree

5 files changed

+12
-96
lines changed

5 files changed

+12
-96
lines changed

Diff for: docs/resources/project.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ resource "sentry_project" "default" {
5959
### Optional
6060

6161
- `client_security` (Attributes) Configure origin URLs which Sentry should accept events from. This is used for communication with clients like [sentry-javascript](https://github.com/getsentry/sentry-javascript). (see [below for nested schema](#nestedatt--client_security))
62-
- `default_key` (Boolean) Whether to create a default key. By default, Sentry will create a key for you. If you wish to manage keys manually, set this to false and create keys using the `sentry_key` resource.
62+
- `default_key` (Boolean) Whether to create a default key on project creation. By default, Sentry will create a key for you. If you wish to manage keys manually, set this to false and create keys using the `sentry_key` resource. Note that this only takes effect on project creation, not on project update.
6363
- `default_rules` (Boolean) Whether to create a default issue alert. Defaults to true where the behavior is to alert the user on every new issue.
6464
- `digests_max_delay` (Number) The maximum amount of time (in seconds) to wait between scheduling digests for delivery.
6565
- `digests_min_delay` (Number) The minimum amount of time (in seconds) to wait between scheduling digests for delivery after the initial scheduling.

Diff for: internal/provider/resource_project.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (r *ProjectResource) Schema(ctx context.Context, req resource.SchemaRequest
242242
},
243243
},
244244
"default_key": schema.BoolAttribute{
245-
Description: "Whether to create a default key. By default, Sentry will create a key for you. If you wish to manage keys manually, set this to false and create keys using the `sentry_key` resource.",
245+
Description: "Whether to create a default key on project creation. By default, Sentry will create a key for you. If you wish to manage keys manually, set this to false and create keys using the `sentry_key` resource. Note that this only takes effect on project creation, not on project update.",
246246
Optional: true,
247247
PlanModifiers: []planmodifier.Bool{
248248
boolplanmodifier.UseStateForUnknown(),
@@ -793,14 +793,6 @@ func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest
793793
return
794794
}
795795

796-
// If the default key is set to false, remove the default key
797-
if !plan.DefaultKey.IsNull() && !plan.DefaultKey.ValueBool() {
798-
if err := r.removeDefaultKey(ctx, plan.Organization.ValueString(), *httpRespUpdate.JSON200); err != nil {
799-
resp.Diagnostics.Append(diagutils.NewClientError("remove default key", err))
800-
return
801-
}
802-
}
803-
804796
// Update teams
805797
if !plan.Teams.Equal(state.Teams) {
806798
var planTeams, stateTeams []string

Diff for: internal/provider/resource_project_test.go

-80
Original file line numberDiff line numberDiff line change
@@ -574,86 +574,6 @@ func TestAccProjectResource_noDefaultKeyOnCreate(t *testing.T) {
574574
})
575575
}
576576

577-
func TestAccProjectResource_noDefaultKeyOnUpdate(t *testing.T) {
578-
teamName := acctest.RandomWithPrefix("tf-team")
579-
projectName := acctest.RandomWithPrefix("tf-project")
580-
rn := "sentry_project.test"
581-
582-
checks := []statecheck.StateCheck{
583-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("id"), knownvalue.NotNull()),
584-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("organization"), knownvalue.StringExact(acctest.TestOrganization)),
585-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("teams"), knownvalue.SetExact([]knownvalue.Check{knownvalue.StringExact(teamName)})),
586-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("name"), knownvalue.StringExact(projectName)),
587-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("slug"), knownvalue.NotNull()),
588-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("platform"), knownvalue.Null()),
589-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("default_rules"), knownvalue.Null()),
590-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("internal_id"), knownvalue.NotNull()),
591-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("features"), knownvalue.NotNull()),
592-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("digests_min_delay"), knownvalue.Int64Exact(300)),
593-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("digests_max_delay"), knownvalue.Int64Exact(1800)),
594-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("resolve_age"), knownvalue.Int64Exact(0)),
595-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("filters"), knownvalue.ObjectExact(map[string]knownvalue.Check{
596-
"blacklisted_ips": knownvalue.SetSizeExact(0),
597-
"releases": knownvalue.SetSizeExact(0),
598-
"error_messages": knownvalue.SetSizeExact(0),
599-
})),
600-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("fingerprinting_rules"), knownvalue.StringExact("")),
601-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("grouping_enhancements"), knownvalue.StringExact("")),
602-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("client_security"), knownvalue.ObjectExact(map[string]knownvalue.Check{
603-
"allowed_domains": knownvalue.SetExact([]knownvalue.Check{
604-
knownvalue.StringExact("*"),
605-
}),
606-
"scrape_javascript": knownvalue.Bool(true),
607-
"security_token": knownvalue.NotNull(),
608-
"security_token_header": knownvalue.StringExact(""),
609-
"verify_tls_ssl": knownvalue.Bool(false),
610-
})),
611-
}
612-
613-
resource.Test(t, resource.TestCase{
614-
PreCheck: func() { acctest.PreCheck(t) },
615-
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
616-
CheckDestroy: testAccCheckProjectDestroy,
617-
Steps: []resource.TestStep{
618-
{
619-
Config: testAccProjectResourceConfig(testAccProjectResourceConfigData{
620-
TeamName: teamName,
621-
ProjectName: projectName,
622-
}) + `
623-
data "sentry_all_keys" "test" {
624-
organization = sentry_project.test.organization
625-
project = sentry_project.test.slug
626-
}
627-
`,
628-
ConfigStateChecks: append(
629-
checks,
630-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("default_key"), knownvalue.Null()),
631-
statecheck.ExpectKnownValue("data.sentry_all_keys.test", tfjsonpath.New("keys"), knownvalue.ListSizeExact(1)),
632-
),
633-
},
634-
{
635-
Config: testAccProjectResourceConfig(testAccProjectResourceConfigData{
636-
TeamName: teamName,
637-
ProjectName: projectName,
638-
Extras: `
639-
default_key = false
640-
`,
641-
}) + `
642-
data "sentry_all_keys" "test" {
643-
organization = sentry_project.test.organization
644-
project = sentry_project.test.slug
645-
}
646-
`,
647-
ConfigStateChecks: append(
648-
checks,
649-
statecheck.ExpectKnownValue(rn, tfjsonpath.New("default_key"), knownvalue.Bool(false)),
650-
statecheck.ExpectKnownValue("data.sentry_all_keys.test", tfjsonpath.New("keys"), knownvalue.ListSizeExact(0)),
651-
),
652-
},
653-
},
654-
})
655-
}
656-
657577
func TestAccProjectResource_validation(t *testing.T) {
658578
teamName := acctest.RandomWithPrefix("tf-team")
659579
projectName := acctest.RandomWithPrefix("tf-project")

Diff for: internal/sentrydata/generate.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def parse_issues_grouptype() -> dict[str, ResultData[Any]]:
143143
case ast.Assign(
144144
targets=[ast.Name(id=id)],
145145
value=ast.Constant(value=value),
146-
) if id.upper() == id:
146+
) if (
147+
id.upper() == id
148+
):
147149
name = id.replace("_", " ").title().replace(" ", "_")
148150
out["IssueGroupCategories"].result.append(name)
149151
out["IssueGroupCategoryNameToId"].result[name] = str(value)
@@ -160,8 +162,8 @@ def parse_rules_conditions_event_attribute() -> dict[str, ResultData[Any]]:
160162
out: dict[str, ResultData[Any]] = {}
161163
for node in ast.walk(data.tree):
162164
match node:
163-
case ast.Assign(
164-
targets=[ast.Name(id="ATTR_CHOICES")],
165+
case ast.AnnAssign(
166+
target=ast.Name(id="ATTR_CHOICES"),
165167
value=ast.Dict(keys=keys),
166168
):
167169
out["EventAttributes"] = ResultData(
@@ -199,7 +201,9 @@ def parse_rules_match() -> dict[str, ResultData[Any]]:
199201
case ast.Assign(
200202
targets=[ast.Name(id=id)],
201203
value=ast.Constant(value=value),
202-
) if id.upper() == id:
204+
) if (
205+
id.upper() == id
206+
):
203207
out["MatchTypes"].result.append(id)
204208
out["MatchTypeNameToId"].result[id] = value
205209
out["MatchTypeIdToName"].result[value] = id
@@ -234,7 +238,7 @@ def extract_types(classdef: ast.ClassDef) -> list[str]:
234238
match elt:
235239
case ast.Tuple(
236240
elts=[ast.Name(id=id), ast.Constant(value=value)]
237-
) if id.upper() == id:
241+
) if (id.upper() == id):
238242
out.append(value)
239243
case _:
240244
pass

Diff for: internal/sentrydata/sentrydata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var DashboardWidgetDisplayTypes = []string{
184184
"top_n",
185185
}
186186

187-
// https://github.com/getsentry/sentry/blob/master/src/sentry/models/project.py#L60-L165
187+
// https://github.com/getsentry/sentry/blob/master/src/sentry/models/project.py#L64-L169
188188
var Platforms = []string{
189189
"other",
190190
"android",

0 commit comments

Comments
 (0)