@@ -201,6 +201,63 @@ resource "sentry_issue_alert" "test" {
201
201
})
202
202
}
203
203
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
+
204
261
func testAccCheckIssueAlertDestroy (s * terraform.State ) error {
205
262
for _ , rs := range s .RootModule ().Resources {
206
263
if rs .Type != "sentry_issue_alert" {
@@ -252,6 +309,44 @@ func testAccCheckIssueAlertExists(n string, alertId *string) resource.TestCheckF
252
309
}
253
310
}
254
311
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
+
255
350
func testAccIssueAlertConfig (teamName string , projectName string , alertName string ) string {
256
351
return testAccOrganizationDataSourceConfig + fmt .Sprintf (`
257
352
resource "sentry_team" "test" {
0 commit comments