From 397e2240d155106673e13c100822ddb0f69ee357 Mon Sep 17 00:00:00 2001 From: Garret Wyman Date: Fri, 31 Jan 2025 05:34:20 -0500 Subject: [PATCH] Alerting: Adding color option to slack contact point (#2010) * Adding color option to slack contact point * Generating docs --- docs/resources/contact_point.md | 1 + .../resources/grafana_contact_point/_acc_receiver_types.tf | 1 + .../grafana/resource_alerting_contact_point_notifiers.go | 7 +++++++ .../grafana/resource_alerting_contact_point_test.go | 1 + 4 files changed, 10 insertions(+) diff --git a/docs/resources/contact_point.md b/docs/resources/contact_point.md index 058b2f72a..da5e822c8 100644 --- a/docs/resources/contact_point.md +++ b/docs/resources/contact_point.md @@ -358,6 +358,7 @@ Read-Only: Optional: +- `color` (String) Templated color of the slack message. - `disable_resolve_message` (Boolean) Whether to disable sending resolve messages. Defaults to `false`. - `endpoint_url` (String) Use this to override the Slack API endpoint URL to send requests to. - `icon_emoji` (String) The name of a Slack workspace emoji to use as the bot icon. diff --git a/examples/resources/grafana_contact_point/_acc_receiver_types.tf b/examples/resources/grafana_contact_point/_acc_receiver_types.tf index 752b5dda2..b16748e6b 100644 --- a/examples/resources/grafana_contact_point/_acc_receiver_types.tf +++ b/examples/resources/grafana_contact_point/_acc_receiver_types.tf @@ -118,6 +118,7 @@ resource "grafana_contact_point" "receiver_types" { mention_channel = "here" mention_users = "user" mention_groups = "group" + color = "color" } teams { diff --git a/internal/resources/grafana/resource_alerting_contact_point_notifiers.go b/internal/resources/grafana/resource_alerting_contact_point_notifiers.go index fee1ef7e3..ed34d56a8 100644 --- a/internal/resources/grafana/resource_alerting_contact_point_notifiers.go +++ b/internal/resources/grafana/resource_alerting_contact_point_notifiers.go @@ -1514,6 +1514,11 @@ func (s slackNotifier) schema() *schema.Resource { Optional: true, Description: "Comma-separated list of groups to mention in the message.", } + r.Schema["color"] = &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Templated color of the slack message.", + } return r } @@ -1533,6 +1538,7 @@ func (s slackNotifier) pack(p *models.EmbeddedContactPoint, data *schema.Resourc packNotifierStringField(&settings, ¬ifier, "mentionChannel", "mention_channel") packNotifierStringField(&settings, ¬ifier, "mentionUsers", "mention_users") packNotifierStringField(&settings, ¬ifier, "mentionGroups", "mention_groups") + packNotifierStringField(&settings, ¬ifier, "color", "color") packSecureFields(notifier, getNotifierConfigFromStateWithUID(data, s, p.UID), s.meta().secureFields) @@ -1557,6 +1563,7 @@ func (s slackNotifier) unpack(raw interface{}, name string) *models.EmbeddedCont unpackNotifierStringField(&json, &settings, "mention_channel", "mentionChannel") unpackNotifierStringField(&json, &settings, "mention_users", "mentionUsers") unpackNotifierStringField(&json, &settings, "mention_groups", "mentionGroups") + unpackNotifierStringField(&json, &settings, "color", "color") return &models.EmbeddedContactPoint{ UID: uid, diff --git a/internal/resources/grafana/resource_alerting_contact_point_test.go b/internal/resources/grafana/resource_alerting_contact_point_test.go index a14c91bf4..5ebda6943 100644 --- a/internal/resources/grafana/resource_alerting_contact_point_test.go +++ b/internal/resources/grafana/resource_alerting_contact_point_test.go @@ -261,6 +261,7 @@ func TestAccContactPoint_notifiers(t *testing.T) { resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.mention_channel", "here"), resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.mention_users", "user"), resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.mention_groups", "group"), + resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.color", "color"), // teams resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "teams.#", "1"), resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "teams.0.url", "http://teams-webhook"),