diff --git a/docs/data-sources/metric_alert.md b/docs/data-sources/metric_alert.md index fd7338a77..f7854dff3 100644 --- a/docs/data-sources/metric_alert.md +++ b/docs/data-sources/metric_alert.md @@ -42,6 +42,7 @@ resource "sentry_metric_alert" "copy" { type = action.value.type target_type = action.value.target_type target_identifier = action.value.target_identifier + integration_id = action.value.integration_id } } @@ -99,6 +100,7 @@ Read-Only: Read-Only: - `id` (String) +- `integration_id` (Number) - `target_identifier` (String) - `target_type` (String) - `type` (String) diff --git a/docs/index.md b/docs/index.md index ca0236c08..127458049 100644 --- a/docs/index.md +++ b/docs/index.md @@ -270,6 +270,12 @@ output "issue_alert_url" { # Metric alert # +data "sentry_organization_integration" "slack" { + organization = "organization" + provider_key = "slack" + name = "Organization" // corresponds to Slack's name of your organisation +} + resource "sentry_metric_alert" "main" { organization = sentry_project.main.organization project = sentry_project.main.id @@ -292,6 +298,18 @@ resource "sentry_metric_alert" "main" { threshold_type = 0 } + trigger { + action { + type = "slack" + target_type = "specific" + target_identifier = "#slack-channel" + integration_id = data.sentry_organization_integration.slack.id + } + alert_threshold = 300 + label = "critical" + threshold_type = 0 + } + trigger { alert_threshold = 100 label = "warning" diff --git a/docs/resources/metric_alert.md b/docs/resources/metric_alert.md index 1d5fdc375..1d9b86c0a 100644 --- a/docs/resources/metric_alert.md +++ b/docs/resources/metric_alert.md @@ -13,6 +13,12 @@ Sentry Metric Alert resource. ## Example Usage ```terraform +data "sentry_organization_integration" "slack" { + organization = "organization" + provider_key = "slack" + name = "organization-slack" +} + resource "sentry_metric_alert" "main" { organization = sentry_project.main.organization project = sentry_project.main.id @@ -36,6 +42,18 @@ resource "sentry_metric_alert" "main" { threshold_type = 0 } + trigger { + action { + type = "slack" + target_type = "specific" + target_identifier = "#slack-channel" + integration_id = data.sentry_organization_integration.slack.id + } + alert_threshold = 300 + label = "critical" + threshold_type = 0 + } + trigger { alert_threshold = 100 label = "warning" @@ -99,6 +117,10 @@ Required: - `target_type` (String) - `type` (String) +Optional: + +- `integration_id` (Number) + Read-Only: - `id` (String) The ID of this resource. diff --git a/examples/data-sources/sentry_metric_alert/data-source.tf b/examples/data-sources/sentry_metric_alert/data-source.tf index c2b8349e1..5450963b3 100644 --- a/examples/data-sources/sentry_metric_alert/data-source.tf +++ b/examples/data-sources/sentry_metric_alert/data-source.tf @@ -27,6 +27,7 @@ resource "sentry_metric_alert" "copy" { type = action.value.type target_type = action.value.target_type target_identifier = action.value.target_identifier + integration_id = action.value.integration_id } } diff --git a/go.mod b/go.mod index 2db0d4090..a12e0ffa2 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/canva/terraform-provider-sentry go 1.18 -replace github.com/jianyuan/go-sentry/v2 => github.com/canva/go-sentry v1.4.1 +replace github.com/jianyuan/go-sentry/v2 => github.com/canva/go-sentry v1.4.2 require ( github.com/google/go-cmp v0.5.8 diff --git a/go.sum b/go.sum index c6ef41bde..b851025c4 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/canva/go-sentry v1.4.1 h1:ZkIN9jHxekFItfYcEMtUK4I5HpqsEZb0PdhTMAZp1B8= -github.com/canva/go-sentry v1.4.1/go.mod h1:B2sP4gGg/R6gdfVr9RtZ/9R7L0gFGKieOfAAjlDyqiA= +github.com/canva/go-sentry v1.4.2 h1:rdtVl5qRFo09cn5OvmHK9lFoqSrg6TZ1A2dsmCNS3HA= +github.com/canva/go-sentry v1.4.2/go.mod h1:B2sP4gGg/R6gdfVr9RtZ/9R7L0gFGKieOfAAjlDyqiA= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= diff --git a/sentry/data_source_sentry_metric_alert.go b/sentry/data_source_sentry_metric_alert.go index 0a863dacd..8178f03d7 100644 --- a/sentry/data_source_sentry_metric_alert.go +++ b/sentry/data_source_sentry_metric_alert.go @@ -107,6 +107,10 @@ func dataSourceSentryMetricAlert() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "integration_id": { + Type: schema.TypeInt, + Optional: true, + }, }, }, }, diff --git a/sentry/resource_sentry_metric_alert.go b/sentry/resource_sentry_metric_alert.go index 6d7594c95..48130ea84 100644 --- a/sentry/resource_sentry_metric_alert.go +++ b/sentry/resource_sentry_metric_alert.go @@ -118,6 +118,10 @@ func resourceSentryMetricAlert() *schema.Resource { Type: schema.TypeString, Required: true, }, + "integration_id": { + Type: schema.TypeInt, + Optional: true, + }, }, }, }, @@ -340,6 +344,9 @@ func expandMetricAlertTriggerActions(actionList []interface{}) []*sentry.MetricA action.ID = sentry.String(v) } } + if v, ok := actionMap["integration_id"].(int); ok && v != 0 { + action.IntegrationID = sentry.Int(v) + } actions = append(actions, action) } return actions @@ -376,8 +383,11 @@ 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 } diff --git a/sentry/resource_sentry_metric_alert_test.go b/sentry/resource_sentry_metric_alert_test.go index 22abcf585..1242e3a68 100644 --- a/sentry/resource_sentry_metric_alert_test.go +++ b/sentry/resource_sentry_metric_alert_test.go @@ -132,6 +132,7 @@ resource "sentry_metric_alert" "test" { type = "email" target_type = "team" target_identifier = sentry_team.test.internal_id + integration_id = 32 } alert_threshold = 1000