Skip to content

Commit 9a5e14b

Browse files
authored
Add webhook message and title fields (#875)
1 parent 7735dd4 commit 9a5e14b

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

docs/resources/contact_point.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ Optional:
389389
- `disable_resolve_message` (Boolean) Whether to disable sending resolve messages. Defaults to `false`.
390390
- `http_method` (String) The HTTP method to use in the request. Defaults to `POST`.
391391
- `max_alerts` (Number) The maximum number of alerts to send in a single request. This can be helpful in limiting the size of the request body. The default is 0, which indicates no limit.
392+
- `message` (String) Custom message. You can use template variables.
392393
- `settings` (Map of String, Sensitive) Additional custom properties to attach to the notifier. Defaults to `map[]`.
394+
- `title` (String) Templated title of the message.
393395

394396
Read-Only:
395397

examples/resources/grafana_contact_point/_acc_receiver_types.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ resource "grafana_contact_point" "receiver_types" {
125125
basic_auth_user = "user"
126126
basic_auth_password = "password"
127127
max_alerts = 100
128+
message = "Custom message"
129+
title = "Custom title"
128130
}
129131

130132
wecom {

internal/resources/grafana/resource_alerting_contact_point_notifiers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,16 @@ func (w webhookNotifier) schema() *schema.Resource {
14051405
Optional: true,
14061406
Description: "The maximum number of alerts to send in a single request. This can be helpful in limiting the size of the request body. The default is 0, which indicates no limit.",
14071407
}
1408+
r.Schema["message"] = &schema.Schema{
1409+
Type: schema.TypeString,
1410+
Optional: true,
1411+
Description: "Custom message. You can use template variables.",
1412+
}
1413+
r.Schema["title"] = &schema.Schema{
1414+
Type: schema.TypeString,
1415+
Optional: true,
1416+
Description: "Templated title of the message.",
1417+
}
14081418
return r
14091419
}
14101420

@@ -1417,6 +1427,8 @@ func (w webhookNotifier) pack(p gapi.ContactPoint) (interface{}, error) {
14171427
packNotifierStringField(&p.Settings, &notifier, "password", "basic_auth_password")
14181428
packNotifierStringField(&p.Settings, &notifier, "authorization_scheme", "authorization_scheme")
14191429
packNotifierStringField(&p.Settings, &notifier, "authorization_credentials", "authorization_credentials")
1430+
packNotifierStringField(&p.Settings, &notifier, "message", "message")
1431+
packNotifierStringField(&p.Settings, &notifier, "title", "title")
14201432
if v, ok := p.Settings["maxAlerts"]; ok && v != nil {
14211433
switch typ := v.(type) {
14221434
case int:
@@ -1443,6 +1455,8 @@ func (w webhookNotifier) unpack(raw interface{}, name string) gapi.ContactPoint
14431455
unpackNotifierStringField(&json, &settings, "basic_auth_password", "password")
14441456
unpackNotifierStringField(&json, &settings, "authorization_scheme", "authorization_scheme")
14451457
unpackNotifierStringField(&json, &settings, "authorization_credentials", "authorization_credentials")
1458+
unpackNotifierStringField(&json, &settings, "message", "message")
1459+
unpackNotifierStringField(&json, &settings, "title", "title")
14461460
if v, ok := json["max_alerts"]; ok && v != nil {
14471461
switch typ := v.(type) {
14481462
case int:

internal/resources/grafana/resource_alerting_contact_point_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ func TestAccContactPoint_notifiers(t *testing.T) {
262262
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "webhook.0.basic_auth_user", "user"),
263263
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "webhook.0.basic_auth_password", "[REDACTED]"),
264264
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "webhook.0.max_alerts", "100"),
265+
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "webhook.0.message", "Custom message"),
266+
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "webhook.0.title", "Custom title"),
265267
// wecom
266268
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "wecom.#", "1"),
267269
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "wecom.0.url", "[REDACTED]"),

0 commit comments

Comments
 (0)