Skip to content

Commit

Permalink
Updated metric alert to include integration id for slack action (#39)
Browse files Browse the repository at this point in the history
* feat: add integration ID to metric alert

* docs: add more docs

* Update docs/index.md

* Update docs/resources/metric_alert.md

* Update sentry/resource_sentry_metric_alert.go

* Update sentry/resource_sentry_metric_alert_test.go

* deps: use 1.4.2 of go-sentry
  • Loading branch information
taj-p authored Sep 27, 2022
1 parent 5c020cd commit 07a988a
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/data-sources/metric_alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -99,6 +100,7 @@ Read-Only:
Read-Only:

- `id` (String)
- `integration_id` (Number)
- `target_identifier` (String)
- `target_type` (String)
- `type` (String)
Expand Down
18 changes: 18 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions docs/resources/metric_alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -99,6 +117,10 @@ Required:
- `target_type` (String)
- `type` (String)

Optional:

- `integration_id` (Number)

Read-Only:

- `id` (String) The ID of this resource.
Expand Down
1 change: 1 addition & 0 deletions examples/data-sources/sentry_metric_alert/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions sentry/data_source_sentry_metric_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func dataSourceSentryMetricAlert() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"integration_id": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
Expand Down
10 changes: 10 additions & 0 deletions sentry/resource_sentry_metric_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func resourceSentryMetricAlert() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"integration_id": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions sentry/resource_sentry_metric_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07a988a

Please sign in to comment.