diff --git a/client/recipient.go b/client/recipient.go index 66e27b2e..df351d52 100644 --- a/client/recipient.go +++ b/client/recipient.go @@ -77,12 +77,13 @@ type RecipientType string // Declaration of recipient types const ( - RecipientTypeEmail RecipientType = "email" - RecipientTypePagerDuty RecipientType = "pagerduty" - RecipientTypeSlack RecipientType = "slack" - RecipientTypeWebhook RecipientType = "webhook" - RecipientTypeMarker RecipientType = "marker" - RecipientTypeMSTeams RecipientType = "msteams" + RecipientTypeEmail RecipientType = "email" + RecipientTypePagerDuty RecipientType = "pagerduty" + RecipientTypeSlack RecipientType = "slack" + RecipientTypeWebhook RecipientType = "webhook" + RecipientTypeMarker RecipientType = "marker" + RecipientTypeMSTeams RecipientType = "msteams" + RecipientTypeMSTeamsWorkflow RecipientType = "msteams_workflow" ) // PagerDutySeverity holds all the possible PD Severity types @@ -111,6 +112,7 @@ func RecipientTypes() []RecipientType { RecipientTypeSlack, RecipientTypeWebhook, RecipientTypeMSTeams, + RecipientTypeMSTeamsWorkflow, } } diff --git a/client/recipient_test.go b/client/recipient_test.go index eecd1d4e..7a88a3c6 100644 --- a/client/recipient_test.go +++ b/client/recipient_test.go @@ -102,11 +102,18 @@ func TestRecipientsWebhooksandMSTeams(t *testing.T) { WebhookURL: "https://corp.office.com/webhook", }, }, + { + Type: client.RecipientTypeMSTeamsWorkflow, + Details: client.RecipientDetails{ + WebhookName: test.RandomStringWithPrefix("test.", 10), + WebhookURL: "https://mycorp.westus.logic.azure.com/workflows/12345", + }, + }, } for _, tr := range testRcpts { r, err := c.Recipients.Create(ctx, &tr) - require.NoError(t, err) + require.NoError(t, err, "failed to create %s recipient", tr.Type) t.Cleanup(func() { _ = c.Recipients.Delete(ctx, r.ID) }) diff --git a/docs/data-sources/recipient.md b/docs/data-sources/recipient.md index a739c99b..34e6c16f 100644 --- a/docs/data-sources/recipient.md +++ b/docs/data-sources/recipient.md @@ -54,19 +54,20 @@ resource "honeycombio_trigger" "example" { The following arguments are supported: -* `type` - (Required) The type of recipient, allowed types are `email`, `pagerduty`, `msteams`, `slack` and `webhook`. +* `type` - (Required) The type of recipient, allowed types are `email`, `pagerduty`, `msteams`, `msteams_workflow`, `slack` and `webhook`. * `dataset` - (Optional) Deprecated: recipients are now a Team-level construct. Any provided value will be ignored. * `detail_filter` - (Optional) a block to further filter recipients as described below. * `target` - (Optional) Deprecated: use `detail_filter` instead. The target of the recipient, this has another meaning depending on the type of recipient (see the table below). -Type | Target -----------|------------------------- -email | an email address -marker | name of the marker -msteams | name of the integration -pagerduty | _N/A_ -slack | name of the channel -webhook | name of the webhook +Type | Target +-----------------|------------------------- +email | an email address +marker | name of the marker +msteams | name of the integration +msteams_workflow | name of the integration +pagerduty | _N/A_ +slack | name of the channel +webhook | name of the webhook To further filter the recipient results, a `detail_filter` block can be provided which accepts the following arguments: @@ -85,6 +86,6 @@ In addition to all arguments above, the following attributes are exported: * `channel` - The Slack recipient's channel -- if of type `slack`. * `name` - The webhook recipient's name -- if of type `webhook` or `msteams`. * `secret` - (Sensitive) The webhook recipient's secret -- if of type `webhook`. -* `url` - The webhook recipient's URL - if of type `webhook` or `msteams`. +* `url` - The webhook recipient's URL - if of type `webhook`, `msteams` or `msteams_workflow`. * `integration_key` - (Sensitive) The PagerDuty recipient's integration key -- if of type `pagerduty`. * `integration_name` - The PagerDuty recipient's inregration name -- if of type `pagerduty`. diff --git a/docs/data-sources/recipients.md b/docs/data-sources/recipients.md index 46a387ba..b5599f0b 100644 --- a/docs/data-sources/recipients.md +++ b/docs/data-sources/recipients.md @@ -25,7 +25,7 @@ data "honeycombio_recipients" "example-dot-com" { The following arguments are supported: -* `type` - (Optional) The type of recipient, allowed types are `email`, `pagerduty`, `msteams`, `slack` and `webhook`. +* `type` - (Optional) The type of recipient, allowed types are `email`, `pagerduty`, `msteams`, `msteams_workflow`, `slack` and `webhook`. * `detail_filter` - (Optional) a block to further filter recipients as described below. `name` must be set when providing a filter. To further filter the recipient results, a `detail_filter` block can be provided which accepts the following arguments: diff --git a/docs/resources/msteams_recipient.md b/docs/resources/msteams_recipient.md index 76555965..e78c7f07 100644 --- a/docs/resources/msteams_recipient.md +++ b/docs/resources/msteams_recipient.md @@ -2,6 +2,9 @@ `honeycombio_msteams_recipient` allows you to define and manage an MSTeams recipient that can be used by Triggers or BurnAlerts notifications. +-> **NOTE** Microsoft has deprecated Teams Incoming Webhooks. + It is recommended you recreate your Teams recipients with the `honeycombio_msteams_workflow_recipient` resource. + ## Example Usage ```hcl diff --git a/docs/resources/msteams_workflow_recipient.md b/docs/resources/msteams_workflow_recipient.md new file mode 100644 index 00000000..027e73a4 --- /dev/null +++ b/docs/resources/msteams_workflow_recipient.md @@ -0,0 +1,33 @@ +# Resource: honeycombio_msteams_workflow_recipient + +`honeycombio_msteams_workflow_recipient` allows you to define and manage an MSTeams Workflows recipient that can be used by Triggers or BurnAlerts notifications. + +## Example Usage + +```hcl +resource "honeycombio_msteams_workflow_recipient" "prod" { + name = "Production Alerts" + url = "https://mycorp.westus.logic.azure.com/workflows/123456" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the recipient. +* `url` - (Required) The MSTeams Workflow URL to send the notification to. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID of the recipient. + +## Import + +MSTeams Workflow Recipients can be imported by their ID, e.g. + +``` +$ terraform import honeycombio_msteams_workflow_recipient.my_recipient nx2zsefB1cX +``` diff --git a/honeycombio/data_source_recipient.go b/honeycombio/data_source_recipient.go index cf6a8c30..d706ac45 100644 --- a/honeycombio/data_source_recipient.go +++ b/honeycombio/data_source_recipient.go @@ -175,7 +175,7 @@ func dataSourceHoneycombioRecipientRead(ctx context.Context, d *schema.ResourceD d.Set("address", rcpt.Details.EmailAddress) case honeycombio.RecipientTypeSlack: d.Set("channel", rcpt.Details.SlackChannel) - case honeycombio.RecipientTypeMSTeams: + case honeycombio.RecipientTypeMSTeams, honeycombio.RecipientTypeMSTeamsWorkflow: d.Set("name", rcpt.Details.WebhookName) d.Set("url", rcpt.Details.WebhookURL) case honeycombio.RecipientTypeWebhook: diff --git a/honeycombio/data_source_recipient_test.go b/honeycombio/data_source_recipient_test.go index 7f3ec9d4..a8a23337 100644 --- a/honeycombio/data_source_recipient_test.go +++ b/honeycombio/data_source_recipient_test.go @@ -66,10 +66,10 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) { }, }, { - Type: honeycombio.RecipientTypeMSTeams, + Type: honeycombio.RecipientTypeMSTeamsWorkflow, Details: honeycombio.RecipientDetails{ WebhookName: test.RandomStringWithPrefix("test.", 16), - WebhookURL: "https://outlook.office.com/webhook/12345", + WebhookURL: "https://mycorp.westus.logic.azure.com/workflows/12345", }, }, } @@ -131,7 +131,7 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) { Config: testAccRecipientWithFilterValue("msteams", "name", testRecipients[7].Details.WebhookName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.honeycombio_recipient.test", "name", testRecipients[7].Details.WebhookName), - resource.TestCheckResourceAttr("data.honeycombio_recipient.test", "url", "https://outlook.office.com/webhook/12345"), + resource.TestCheckResourceAttr("data.honeycombio_recipient.test", "url", "https://mycorp.westus.logic.azure.com/workflows/12345"), ), }, { diff --git a/honeycombio/provider.go b/honeycombio/provider.go index bfa89d51..48b3d8f9 100644 --- a/honeycombio/provider.go +++ b/honeycombio/provider.go @@ -60,20 +60,21 @@ func Provider(version string) *schema.Provider { "honeycombio_recipients": dataSourceHoneycombioRecipients(), }, ResourcesMap: map[string]*schema.Resource{ - "honeycombio_board": newBoard(), - "honeycombio_column": newColumn(), - "honeycombio_dataset": newDataset(), - "honeycombio_dataset_definition": newDatasetDefinition(), - "honeycombio_derived_column": newDerivedColumn(), - "honeycombio_marker": newMarker(), - "honeycombio_marker_setting": newMarkerSetting(), - "honeycombio_query_annotation": newQueryAnnotation(), - "honeycombio_email_recipient": newEmailRecipient(), - "honeycombio_pagerduty_recipient": newPDRecipient(), - "honeycombio_msteams_recipient": newMSTeamsRecipient(), - "honeycombio_slack_recipient": newSlackRecipient(), - "honeycombio_webhook_recipient": newWebhookRecipient(), - "honeycombio_slo": newSLO(), + "honeycombio_board": newBoard(), + "honeycombio_column": newColumn(), + "honeycombio_dataset": newDataset(), + "honeycombio_dataset_definition": newDatasetDefinition(), + "honeycombio_derived_column": newDerivedColumn(), + "honeycombio_marker": newMarker(), + "honeycombio_marker_setting": newMarkerSetting(), + "honeycombio_query_annotation": newQueryAnnotation(), + "honeycombio_email_recipient": newEmailRecipient(), + "honeycombio_pagerduty_recipient": newPDRecipient(), + "honeycombio_msteams_recipient": newMSTeamsRecipient(), + "honeycombio_msteams_workflow_recipient": newMSTeamsWorkflowRecipient(), + "honeycombio_slack_recipient": newSlackRecipient(), + "honeycombio_webhook_recipient": newWebhookRecipient(), + "honeycombio_slo": newSLO(), }, } diff --git a/honeycombio/resource_msteams_recipient.go b/honeycombio/resource_msteams_recipient.go index 56fac472..9593cc7e 100644 --- a/honeycombio/resource_msteams_recipient.go +++ b/honeycombio/resource_msteams_recipient.go @@ -19,13 +19,14 @@ func newMSTeamsRecipient() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Description: "Honeycomb MSTeams Recipient allows you to define and manage an MSTeams recipient that can be used by Triggers or BurnAlerts notifications.", + DeprecationMessage: "MSTeams Recipient is deprecated. Please use MSTeams Workflow Recipient resource instead.", + Description: "Honeycomb MSTeams Recipient allows you to define and manage an MSTeams recipient that can be used by Triggers or BurnAlerts notifications.", Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, Required: true, - Description: "The name of the MSTeams Integration to create", + Description: "The name of the recipient.", }, "url": { Type: schema.TypeString, diff --git a/honeycombio/resource_msteams_workflow_recipient.go b/honeycombio/resource_msteams_workflow_recipient.go new file mode 100644 index 00000000..a553c63e --- /dev/null +++ b/honeycombio/resource_msteams_workflow_recipient.go @@ -0,0 +1,54 @@ +package honeycombio + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client" +) + +func newMSTeamsWorkflowRecipient() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceMSTeamsWorkflowRecipientCreate, + ReadContext: resourceMSTeamsWorkflowRecipientRead, + UpdateContext: resourceMSTeamsWorkflowRecipientUpdate, + DeleteContext: resourceMSTeamsWorkflowRecipientDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + Description: "Honeycomb MSTeams Workflow Recipient allows you to define and manage an MSTeams Workflows recipient that can be used by Triggers or BurnAlerts notifications.", + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "The name of the recipient.", + }, + "url": { + Type: schema.TypeString, + Required: true, + Description: "The Teams Workflow URL to send the notification to.", + ValidateFunc: validation.IsURLWithHTTPorHTTPS, + }, + }, + } +} + +func resourceMSTeamsWorkflowRecipientCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return createRecipient(ctx, d, meta, honeycombio.RecipientTypeMSTeamsWorkflow) +} + +func resourceMSTeamsWorkflowRecipientRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return readRecipient(ctx, d, meta, honeycombio.RecipientTypeMSTeamsWorkflow) +} + +func resourceMSTeamsWorkflowRecipientUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return updateRecipient(ctx, d, meta, honeycombio.RecipientTypeMSTeamsWorkflow) +} + +func resourceMSTeamsWorkflowRecipientDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return deleteRecipient(ctx, d, meta) +} diff --git a/honeycombio/type_helpers.go b/honeycombio/type_helpers.go index c8acce2e..06459c72 100644 --- a/honeycombio/type_helpers.go +++ b/honeycombio/type_helpers.go @@ -43,7 +43,7 @@ func expandRecipient(t honeycombio.RecipientType, d *schema.ResourceData) (*hone r.Details.PDIntegrationName = d.Get("integration_name").(string) case honeycombio.RecipientTypeSlack: r.Details.SlackChannel = d.Get("channel").(string) - case honeycombio.RecipientTypeMSTeams: + case honeycombio.RecipientTypeMSTeams, honeycombio.RecipientTypeMSTeamsWorkflow: r.Details.WebhookName = d.Get("name").(string) r.Details.WebhookURL = d.Get("url").(string) case honeycombio.RecipientTypeWebhook: @@ -104,7 +104,7 @@ func readRecipient(ctx context.Context, d *schema.ResourceData, meta interface{} d.Set("integration_name", r.Details.PDIntegrationName) case honeycombio.RecipientTypeSlack: d.Set("channel", r.Details.SlackChannel) - case honeycombio.RecipientTypeMSTeams: + case honeycombio.RecipientTypeMSTeams, honeycombio.RecipientTypeMSTeamsWorkflow: d.Set("name", r.Details.WebhookName) d.Set("url", r.Details.WebhookURL) case honeycombio.RecipientTypeWebhook: @@ -201,7 +201,7 @@ func (f *recipientFilter) IsMatch(r honeycombio.Recipient) bool { return f.ValueRegex.MatchString(r.Details.SlackChannel) case honeycombio.RecipientTypePagerDuty: return f.ValueRegex.MatchString(r.Details.PDIntegrationName) - case honeycombio.RecipientTypeWebhook, honeycombio.RecipientTypeMSTeams: + case honeycombio.RecipientTypeWebhook, honeycombio.RecipientTypeMSTeams, honeycombio.RecipientTypeMSTeamsWorkflow: return f.ValueRegex.MatchString(r.Details.WebhookName) || f.ValueRegex.MatchString(r.Details.WebhookURL) } } else if f.Value != nil { @@ -212,7 +212,7 @@ func (f *recipientFilter) IsMatch(r honeycombio.Recipient) bool { return (r.Details.SlackChannel == *f.Value) case honeycombio.RecipientTypePagerDuty: return (r.Details.PDIntegrationName == *f.Value) - case honeycombio.RecipientTypeWebhook, honeycombio.RecipientTypeMSTeams: + case honeycombio.RecipientTypeWebhook, honeycombio.RecipientTypeMSTeams, honeycombio.RecipientTypeMSTeamsWorkflow: return (r.Details.WebhookName == *f.Value) || (r.Details.WebhookURL == *f.Value) } }