From f6deb55e451c6a406d03e02c58285556cc3d2953 Mon Sep 17 00:00:00 2001 From: Brooke Sargent Date: Tue, 3 Sep 2024 13:21:04 -0400 Subject: [PATCH] feat: slack channel regex accepts channel id (#540) ## Which problem is this PR solving? - Closes #533 ## Short description of the changes Updates the Slack channel regex to include channel ids in addition to channels/users beginning with `#` or `@` --- docs/resources/slack_recipient.md | 2 +- honeycombio/resource_slack_recipient.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/resources/slack_recipient.md b/docs/resources/slack_recipient.md index 21c4be2c..97cff5e4 100644 --- a/docs/resources/slack_recipient.md +++ b/docs/resources/slack_recipient.md @@ -14,7 +14,7 @@ resource "honeycombio_slack_recipient" "alerts" { The following arguments are supported: -* `channel` - (Required) The Slack channel or username to send the notification to. Must begin with `#` or `@`. +* `channel` - (Required) The Slack channel or username to send the notification to. Must begin with `#` or `@` or be a valid channel id e.g. `CABC123DEF. ## Attribute Reference diff --git a/honeycombio/resource_slack_recipient.go b/honeycombio/resource_slack_recipient.go index c7d8ac72..12a5c344 100644 --- a/honeycombio/resource_slack_recipient.go +++ b/honeycombio/resource_slack_recipient.go @@ -11,6 +11,8 @@ import ( honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client" ) +var channelRegex = regexp.MustCompile(`^#.*|^@.*|^(C|D|G)[A-Z0-9]{6,}$`) + func newSlackRecipient() *schema.Resource { return &schema.Resource{ CreateContext: resourceSlackRecipientCreate, @@ -26,8 +28,8 @@ func newSlackRecipient() *schema.Resource { "channel": { Type: schema.TypeString, Required: true, - Description: "The Slack channel or username to send the notification to. Must begin with `#` or `@`.", - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(#|@).+`), "channel must begin with `#` or `@`"), + Description: "The Slack channel or username to send the notification to. Must begin with `#` or `@` or be a valid channel id e.g. `CABC123DEF.", + ValidateFunc: validation.StringMatch(channelRegex, "channel must begin with `#` or `@` or be a valid channel id e.g. `CABC123DEF`"), }, }, }