terraform-provider-sentry
terraform-provider-sentry copied to clipboard
Feature request: Configure slack sentry_metric_alert actions
Hello
Whenever I try to configure the following sentry_metric_alert:
resource "sentry_metric_alert" "error_flood" {
organization = var.org_slug
project = var.project_slug
name = "A lot of errors happening."
time_window = 30
dataset = "events"
query = ""
aggregate = "count()"
threshold_type = 0
resolve_threshold = 0
trigger {
alert_threshold = var.alert_threshold_30mins
label = "critical"
threshold_type = 0
action {
target_identifier = var.team_id
target_type = "team"
type = "email"
}
action {
target_identifier = var.slack_channel
target_type = "specific"
type = "slack"
}
}
}
I get the following error:
│ Error: POST https://sentry.io/api/0/projects/companyslug/projectslug/alert-rules/: 400 map[integration:[Integration must be provided for slack]]
│
│ with module.app_alerts.sentry_metric_alert.error_flood_slack,
│ on modules/alert/alert.tf line 1, in resource "sentry_metric_alert" "error_flood_slack":
│ 1: resource "sentry_metric_alert" "error_flood_slack" {
│
So unless I'm doing something wrong, it seems this is not yet possible. I did take a look myself, and it looks like the integrationId is missing in the call. Tried adding this myself to the provider, but then I received an error:
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to module.app_alerts.sentry_metric_alert.error_flood_slack, provider "provider[\"registry.terraform.io/jianyuan/sentry\"]" produced an unexpected new value: Root resource was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
This was with the following changes:
diff --git a/sentry/data_source_sentry_metric_alert.go b/sentry/data_source_sentry_metric_alert.go
index 50b27b0..6b80bf4 100644
--- a/sentry/data_source_sentry_metric_alert.go
+++ b/sentry/data_source_sentry_metric_alert.go
@@ -96,6 +96,9 @@ func dataSourceSentryMetricAlert() *schema.Resource {
"target_identifier": {
Type: schema.TypeString,
Computed: true,
+ }, "integration_id": {
+ Type: schema.TypeInt,
+ Computed: true,
},
},
},
diff --git a/sentry/resource_sentry_metric_alert.go b/sentry/resource_sentry_metric_alert.go
index e438bd8..164f2e1 100644
--- a/sentry/resource_sentry_metric_alert.go
+++ b/sentry/resource_sentry_metric_alert.go
@@ -106,6 +106,10 @@ func resourceSentryMetricAlert() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
+ "integration_id": {
+ Type: schema.TypeInt,
+ Optional: true,
+ },
},
},
},
@@ -318,6 +322,7 @@ func expandMetricAlertTriggerActions(actionList []interface{}) []*sentry.MetricA
Type: sentry.String(actionMap["type"].(string)),
TargetType: sentry.String(actionMap["target_type"].(string)),
TargetIdentifier: sentry.String(actionMap["target_identifier"].(string)),
+ IntegrationID: sentry.Int(actionMap["integration_id"].(int)),
}
if v, ok := actionMap["id"].(string); ok {
if v != "" {
@@ -360,6 +365,7 @@ func flattenMetricAlertTriggerActions(actions []*sentry.MetricAlertTriggerAction
actionMap["type"] = action.Type
actionMap["target_type"] = action.TargetType
actionMap["target_identifier"] = action.TargetIdentifier
+ actionMap["integration_id"] = action.IntegrationID
actionList = append(actionList, actionMap)
}
return actionList
I could also put up a PR if you could advise me of what I'm missing. I have no experience in building terraform providers.
Thanks!
Looks like @GirtsZemitis already made a PR https://github.com/jianyuan/terraform-provider-sentry/pull/196/files with a POC
I think i have the same problem
`resource "sentry_metric_alert" "count_of_event_default_sre" { for_each = toset(var.sre_projects)
organization = var.organization project = each.key name = "A lot of errors last 10 minutes" dataset = "events" query = "" aggregate = "count()" time_window = 10 threshold_type = 0 resolve_threshold = 0 environment = "dev"
trigger { action { type = "slack" target_type = "specific" target_identifier = "${var.slack_channel_sre}" } alert_threshold = 300 label = "critical" threshold_type = 0 } }`
│ Error: POST https://sentry.io/api/0/projects/my-project/sre/alert-rules/: 400 map[integration:[Integration must be provided for slack]] │ │ with sentry_metric_alert.count_of_event_default_sre["sre"], │ on main.tf line 139, in resource "sentry_metric_alert" "count_of_event_default_sre": │ 139: resource "sentry_metric_alert" "count_of_event_default_sre" { │ ╵
@jianyuan can please create new release. You already have fix on main branch. Then you can close the current issue. Thanks
The sentry_organization_integration
data source is already available since v0.10.0.
The next release will include updated docs demonstrating usage. You can get a preview of it here.