Skip to content

Commit 44f5cda

Browse files
Alerting Contact Points: Add SNS notifier (#1295)
* Alerting Contact Points: Add SNS notifier Closes #1075 Tested on Amazon Managed Grafana * go generate
1 parent b58bc6c commit 44f5cda

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

docs/resources/contact_point.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ resource "grafana_contact_point" "my_contact_point" {
5656
- `pushover` (Block Set) A contact point that sends notifications to Pushover. (see [below for nested schema](#nestedblock--pushover))
5757
- `sensugo` (Block Set) A contact point that sends notifications to SensuGo. (see [below for nested schema](#nestedblock--sensugo))
5858
- `slack` (Block Set) A contact point that sends notifications to Slack. (see [below for nested schema](#nestedblock--slack))
59+
- `sns` (Block Set) A contact point that sends notifications to Amazon SNS. Requires Amazon Managed Grafana. (see [below for nested schema](#nestedblock--sns))
5960
- `teams` (Block Set) A contact point that sends notifications to Microsoft Teams. (see [below for nested schema](#nestedblock--teams))
6061
- `telegram` (Block Set) A contact point that sends notifications to Telegram. (see [below for nested schema](#nestedblock--telegram))
6162
- `threema` (Block Set) A contact point that sends notifications to Threema. (see [below for nested schema](#nestedblock--threema))
@@ -375,6 +376,31 @@ Read-Only:
375376
- `uid` (String) The UID of the contact point.
376377

377378

379+
<a id="nestedblock--sns"></a>
380+
### Nested Schema for `sns`
381+
382+
Required:
383+
384+
- `topic` (String) The Amazon SNS topic to send notifications to.
385+
386+
Optional:
387+
388+
- `access_key` (String, Sensitive) AWS access key ID used to authenticate with Amazon SNS.
389+
- `assume_role_arn` (String) The Amazon Resource Name (ARN) of the role to assume to send notifications to Amazon SNS.
390+
- `auth_provider` (String) The authentication provider to use. Valid values are `default`, `arn` and `keys`. Default is `default`. Defaults to `default`.
391+
- `body` (String)
392+
- `disable_resolve_message` (Boolean) Whether to disable sending resolve messages. Defaults to `false`.
393+
- `external_id` (String) The external ID to use when assuming the role.
394+
- `message_format` (String) The format of the message to send. Valid values are `text`, `body` and `json`. Default is `text`. Defaults to `text`.
395+
- `secret_key` (String, Sensitive) AWS secret access key used to authenticate with Amazon SNS.
396+
- `settings` (Map of String, Sensitive) Additional custom properties to attach to the notifier. Defaults to `map[]`.
397+
- `subject` (String)
398+
399+
Read-Only:
400+
401+
- `uid` (String) The UID of the contact point.
402+
403+
378404
<a id="nestedblock--teams"></a>
379405
### Nested Schema for `teams`
380406

internal/resources/grafana/resource_alerting_contact_point.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var notifiers = []notifier{
3232
pushoverNotifier{},
3333
sensugoNotifier{},
3434
slackNotifier{},
35+
snsNotifier{},
3536
teamsNotifier{},
3637
telegramNotifier{},
3738
threemaNotifier{},

internal/resources/grafana/resource_alerting_contact_point_notifiers.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,118 @@ func (s slackNotifier) unpack(raw interface{}, name string) *models.EmbeddedCont
15551555
}
15561556
}
15571557

1558+
type snsNotifier struct{}
1559+
1560+
var _ notifier = (*snsNotifier)(nil)
1561+
1562+
func (s snsNotifier) meta() notifierMeta {
1563+
return notifierMeta{
1564+
field: "sns",
1565+
typeStr: "sns",
1566+
desc: "A contact point that sends notifications to Amazon SNS. Requires Amazon Managed Grafana.",
1567+
secureFields: []string{"access_key", "secret_key"},
1568+
}
1569+
}
1570+
1571+
func (s snsNotifier) schema() *schema.Resource {
1572+
r := commonNotifierResource()
1573+
r.Schema["topic"] = &schema.Schema{
1574+
Type: schema.TypeString,
1575+
Description: "The Amazon SNS topic to send notifications to.",
1576+
Required: true,
1577+
}
1578+
r.Schema["auth_provider"] = &schema.Schema{
1579+
Type: schema.TypeString,
1580+
Optional: true,
1581+
Description: "The authentication provider to use. Valid values are `default`, `arn` and `keys`. Default is `default`.",
1582+
Default: "default",
1583+
ValidateFunc: validation.StringInSlice([]string{"default", "arn", "keys"}, false),
1584+
}
1585+
r.Schema["access_key"] = &schema.Schema{
1586+
Type: schema.TypeString,
1587+
Optional: true,
1588+
Sensitive: true,
1589+
Description: "AWS access key ID used to authenticate with Amazon SNS.",
1590+
}
1591+
r.Schema["secret_key"] = &schema.Schema{
1592+
Type: schema.TypeString,
1593+
Optional: true,
1594+
Sensitive: true,
1595+
Description: "AWS secret access key used to authenticate with Amazon SNS.",
1596+
}
1597+
r.Schema["assume_role_arn"] = &schema.Schema{
1598+
Type: schema.TypeString,
1599+
Optional: true,
1600+
Description: "The Amazon Resource Name (ARN) of the role to assume to send notifications to Amazon SNS.",
1601+
}
1602+
r.Schema["message_format"] = &schema.Schema{
1603+
Type: schema.TypeString,
1604+
Optional: true,
1605+
Description: "The format of the message to send. Valid values are `text`, `body` and `json`. Default is `text`.",
1606+
ValidateFunc: validation.StringInSlice([]string{"text", "body", "json"}, false),
1607+
Default: "text",
1608+
}
1609+
r.Schema["body"] = &schema.Schema{
1610+
Type: schema.TypeString,
1611+
Optional: true,
1612+
}
1613+
r.Schema["subject"] = &schema.Schema{
1614+
Type: schema.TypeString,
1615+
Optional: true,
1616+
}
1617+
r.Schema["external_id"] = &schema.Schema{
1618+
Type: schema.TypeString,
1619+
Optional: true,
1620+
Description: "The external ID to use when assuming the role.",
1621+
}
1622+
1623+
return r
1624+
}
1625+
1626+
func (s snsNotifier) pack(p *models.EmbeddedContactPoint, data *schema.ResourceData) (interface{}, error) {
1627+
notifier := packCommonNotifierFields(p)
1628+
settings := p.Settings.(map[string]interface{})
1629+
1630+
packNotifierStringField(&settings, &notifier, "topic", "topic")
1631+
packNotifierStringField(&settings, &notifier, "authProvider", "auth_provider")
1632+
packNotifierStringField(&settings, &notifier, "accessKey", "access_key")
1633+
packNotifierStringField(&settings, &notifier, "secretKey", "secret_key")
1634+
packNotifierStringField(&settings, &notifier, "assumeRoleARN", "assume_role_arn")
1635+
packNotifierStringField(&settings, &notifier, "messageFormat", "message_format")
1636+
packNotifierStringField(&settings, &notifier, "body", "body")
1637+
packNotifierStringField(&settings, &notifier, "subject", "subject")
1638+
packNotifierStringField(&settings, &notifier, "externalId", "external_id")
1639+
1640+
packSecureFields(notifier, getNotifierConfigFromStateWithUID(data, s, p.UID), s.meta().secureFields)
1641+
1642+
notifier["settings"] = packSettings(p)
1643+
1644+
return notifier, nil
1645+
}
1646+
1647+
func (s snsNotifier) unpack(raw interface{}, name string) *models.EmbeddedContactPoint {
1648+
json := raw.(map[string]interface{})
1649+
uid, disableResolve, settings := unpackCommonNotifierFields(json)
1650+
1651+
unpackNotifierStringField(&json, &settings, "topic", "topic")
1652+
unpackNotifierStringField(&json, &settings, "auth_provider", "authProvider")
1653+
unpackNotifierStringField(&json, &settings, "access_key", "accessKey")
1654+
unpackNotifierStringField(&json, &settings, "secret_key", "secretKey")
1655+
unpackNotifierStringField(&json, &settings, "assume_role_arn", "assumeRoleARN")
1656+
unpackNotifierStringField(&json, &settings, "message_format", "messageFormat")
1657+
unpackNotifierStringField(&json, &settings, "body", "body")
1658+
unpackNotifierStringField(&json, &settings, "subject", "subject")
1659+
unpackNotifierStringField(&json, &settings, "external_id", "externalId")
1660+
1661+
return &models.EmbeddedContactPoint{
1662+
UID: uid,
1663+
Name: name,
1664+
Type: common.Ref(s.meta().typeStr),
1665+
DisableResolveMessage: disableResolve,
1666+
Settings: settings,
1667+
}
1668+
}
1669+
15581670
type teamsNotifier struct{}
15591671

15601672
var _ notifier = (*teamsNotifier)(nil)

0 commit comments

Comments
 (0)