Skip to content

Commit

Permalink
feat: add r/msteams_workflow_recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
jharley committed Aug 7, 2024
1 parent 0233e88 commit 1cbd4db
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 42 deletions.
14 changes: 8 additions & 6 deletions client/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,6 +112,7 @@ func RecipientTypes() []RecipientType {
RecipientTypeSlack,
RecipientTypeWebhook,
RecipientTypeMSTeams,
RecipientTypeMSTeamsWorkflow,
}
}

Expand Down
9 changes: 8 additions & 1 deletion client/recipient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
21 changes: 11 additions & 10 deletions docs/data-sources/recipient.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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`.
2 changes: 1 addition & 1 deletion docs/data-sources/recipients.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/msteams_recipient.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions docs/resources/msteams_workflow_recipient.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion honeycombio/data_source_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions honeycombio/data_source_recipient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
Expand Down Expand Up @@ -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"),
),
},
{
Expand Down
29 changes: 15 additions & 14 deletions honeycombio/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}

Expand Down
5 changes: 3 additions & 2 deletions honeycombio/resource_msteams_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions honeycombio/resource_msteams_workflow_recipient.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 4 additions & 4 deletions honeycombio/type_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 1cbd4db

Please sign in to comment.