Skip to content

Commit 45a1198

Browse files
authored
fix: sentry_issue_alert.conditions empty array (#398)
1 parent 5e14c27 commit 45a1198

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

internal/provider/resource_issue_alert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (m *IssueAlertResourceModel) Fill(organization string, alert sentry.IssueAl
5555
m.FilterMatch = types.StringPointerValue(alert.FilterMatch)
5656
m.Owner = types.StringPointerValue(alert.Owner)
5757

58-
m.Conditions = sentrytypes.NewLossyJsonNull()
58+
m.Conditions = sentrytypes.NewLossyJsonValue("[]")
5959
if len(alert.Conditions) > 0 {
6060
if conditions, err := json.Marshal(alert.Conditions); err == nil {
6161
m.Conditions = sentrytypes.NewLossyJsonValue(string(conditions))

internal/provider/resource_issue_alert_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,63 @@ resource "sentry_issue_alert" "test" {
201201
})
202202
}
203203

204+
func TestAccIssueAlertResource_EmptyArray(t *testing.T) {
205+
rn := "sentry_issue_alert.test"
206+
team := acctest.RandomWithPrefix("tf-team")
207+
project := acctest.RandomWithPrefix("tf-project")
208+
alert := acctest.RandomWithPrefix("tf-issue-alert")
209+
var alertId string
210+
211+
check := func(alert string) resource.TestCheckFunc {
212+
return resource.ComposeTestCheckFunc(
213+
testAccCheckIssueAlertExists(rn, &alertId),
214+
resource.TestCheckResourceAttrWith(rn, "id", func(value string) error {
215+
if alertId != value {
216+
return fmt.Errorf("expected %s, got %s", alertId, value)
217+
}
218+
return nil
219+
}),
220+
resource.TestCheckResourceAttr(rn, "organization", acctest.TestOrganization),
221+
resource.TestCheckResourceAttr(rn, "project", project),
222+
resource.TestCheckResourceAttr(rn, "name", alert),
223+
resource.TestCheckResourceAttr(rn, "action_match", "any"),
224+
resource.TestCheckResourceAttr(rn, "filter_match", "any"),
225+
resource.TestCheckResourceAttr(rn, "frequency", "30"),
226+
resource.TestCheckResourceAttrSet(rn, "conditions"),
227+
resource.TestCheckResourceAttrSet(rn, "actions"),
228+
)
229+
}
230+
231+
resource.Test(t, resource.TestCase{
232+
PreCheck: func() { acctest.PreCheck(t) },
233+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
234+
CheckDestroy: testAccCheckIssueAlertDestroy,
235+
Steps: []resource.TestStep{
236+
{
237+
Config: testAccIssueAlertConfigEmptyArray(team, project, alert),
238+
Check: check(alert),
239+
},
240+
{
241+
Config: testAccIssueAlertConfigEmptyArray(team, project, alert+"-updated"),
242+
Check: check(alert + "-updated"),
243+
},
244+
{
245+
ResourceName: rn,
246+
ImportState: true,
247+
ImportStateIdFunc: func(s *terraform.State) (string, error) {
248+
rs, ok := s.RootModule().Resources[rn]
249+
if !ok {
250+
return "", fmt.Errorf("not found: %s", rn)
251+
}
252+
return buildThreePartID(rs.Primary.Attributes["organization"], rs.Primary.Attributes["project"], rs.Primary.ID), nil
253+
},
254+
ImportStateVerify: true,
255+
ImportStateVerifyIgnore: []string{"actions"},
256+
},
257+
},
258+
})
259+
}
260+
204261
func testAccCheckIssueAlertDestroy(s *terraform.State) error {
205262
for _, rs := range s.RootModule().Resources {
206263
if rs.Type != "sentry_issue_alert" {
@@ -252,6 +309,44 @@ func testAccCheckIssueAlertExists(n string, alertId *string) resource.TestCheckF
252309
}
253310
}
254311

312+
func testAccIssueAlertConfigEmptyArray(teamName string, projectName string, alertName string) string {
313+
return testAccOrganizationDataSourceConfig + fmt.Sprintf(`
314+
resource "sentry_team" "test" {
315+
organization = data.sentry_organization.test.id
316+
name = "%[1]s"
317+
slug = "%[1]s"
318+
}
319+
320+
resource "sentry_project" "test" {
321+
organization = sentry_team.test.organization
322+
teams = [sentry_team.test.id]
323+
name = "%[2]s"
324+
platform = "go"
325+
}
326+
327+
resource "sentry_issue_alert" "test" {
328+
organization = sentry_project.test.organization
329+
project = sentry_project.test.id
330+
name = "%[3]s"
331+
332+
action_match = "any"
333+
filter_match = "any"
334+
frequency = 30
335+
336+
conditions = "[]"
337+
338+
actions = <<EOT
339+
[
340+
{
341+
"id": "sentry.mail.actions.NotifyEmailAction",
342+
"targetType": "IssueOwners"
343+
}
344+
]
345+
EOT
346+
}
347+
`, teamName, projectName, alertName)
348+
}
349+
255350
func testAccIssueAlertConfig(teamName string, projectName string, alertName string) string {
256351
return testAccOrganizationDataSourceConfig + fmt.Sprintf(`
257352
resource "sentry_team" "test" {

0 commit comments

Comments
 (0)