Skip to content

Commit

Permalink
feat: add r/msteams_workflow_recipient (#524)
Browse files Browse the repository at this point in the history
Adds the new `r/msteams_workflow_recipient` resource, deprecates
`r/msteams_recipient`, and removes the ability to create net-new
instances of `r/msteams_recipient`.
  • Loading branch information
jharley authored Aug 12, 2024
1 parent 6713cc3 commit 2806e22
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 61 deletions.
9 changes: 8 additions & 1 deletion client/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ type NotificationRecipientDetails struct {
// RecipientType holds all the possible recipient types.
type RecipientType string

func (t RecipientType) String() string {
return string(t)
}

// Declaration of recipient types
const (
RecipientTypeEmail RecipientType = "email"
RecipientTypePagerDuty RecipientType = "pagerduty"
RecipientTypeSlack RecipientType = "slack"
RecipientTypeWebhook RecipientType = "webhook"
RecipientTypeMarker RecipientType = "marker"
RecipientTypeMSTeams RecipientType = "msteams"
// Deprecated: new recipients must use RecipientTypeMSTeamsWorkflow instead
RecipientTypeMSTeams RecipientType = "msteams"
RecipientTypeMSTeamsWorkflow RecipientType = "msteams_workflow"
)

// PagerDutySeverity holds all the possible PD Severity types
Expand Down Expand Up @@ -111,6 +117,7 @@ func RecipientTypes() []RecipientType {
RecipientTypeSlack,
RecipientTypeWebhook,
RecipientTypeMSTeams,
RecipientTypeMSTeamsWorkflow,
}
}

Expand Down
70 changes: 47 additions & 23 deletions client/recipient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,61 @@ func TestRecipientsWebhooksandMSTeams(t *testing.T) {
ctx := context.Background()
c := newTestClient(t)

testRcpts := []client.Recipient{
testCases := []struct {
rcpt client.Recipient
expectErr bool
}{
{
Type: client.RecipientTypeWebhook,
Details: client.RecipientDetails{
WebhookName: test.RandomStringWithPrefix("test.", 10),
WebhookURL: "https://example.com",
WebhookSecret: "secret",
rcpt: client.Recipient{
Type: client.RecipientTypeWebhook,
Details: client.RecipientDetails{
WebhookName: test.RandomStringWithPrefix("test.", 10),
WebhookURL: "https://example.com",
WebhookSecret: "secret",
},
},
},
{
Type: client.RecipientTypeMSTeams,
Details: client.RecipientDetails{
WebhookName: test.RandomStringWithPrefix("test.", 10),
WebhookURL: "https://corp.office.com/webhook",
rcpt: client.Recipient{
Type: client.RecipientTypeMSTeams,
Details: client.RecipientDetails{
WebhookName: test.RandomStringWithPrefix("test.", 10),
WebhookURL: "https://corp.office.com/webhook",
},
},
expectErr: true, // creation of new MSTeams recipients is not allowed
},
{
rcpt: client.Recipient{
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)
t.Cleanup(func() {
_ = c.Recipients.Delete(ctx, r.ID)
for _, tc := range testCases {
tr := tc.rcpt
t.Run(tr.Type.String(), func(t *testing.T) {
r, err := c.Recipients.Create(ctx, &tr)
t.Cleanup(func() {
_ = c.Recipients.Delete(ctx, r.ID)
})

if tc.expectErr {
require.Error(t, err, "expected error creating %s recipient", tr.Type)
return
}
require.NoError(t, err, "failed to create %s recipient", tr.Type)
r, err = c.Recipients.Get(ctx, r.ID)
require.NoError(t, err)

assert.Equal(t, tr.Type, r.Type)
assert.Equal(t, tr.Details.WebhookName, r.Details.WebhookName)
assert.Equal(t, tr.Details.WebhookURL, r.Details.WebhookURL)
assert.Equal(t, tr.Details.WebhookSecret, r.Details.WebhookSecret)
})

r, err = c.Recipients.Get(ctx, r.ID)
require.NoError(t, err)

assert.Equal(t, tr.Type, r.Type)
assert.Equal(t, tr.Details.WebhookName, r.Details.WebhookName)
assert.Equal(t, tr.Details.WebhookURL, r.Details.WebhookURL)
assert.Equal(t, tr.Details.WebhookSecret, r.Details.WebhookSecret)
}
}
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
4 changes: 4 additions & 0 deletions docs/resources/msteams_recipient.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

`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 Office 365 Connectors.
This resource will no longer allow creation of new recipients.
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: //nolint:staticcheck
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(), // deprecated
"honeycombio_msteams_workflow_recipient": newMSTeamsWorkflowRecipient(),
"honeycombio_slack_recipient": newSlackRecipient(),
"honeycombio_webhook_recipient": newWebhookRecipient(),
"honeycombio_slo": newSLO(),
},
}

Expand Down
49 changes: 49 additions & 0 deletions honeycombio/recipients_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package honeycombio

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/test"
)

// TestAccHoneycombMSTeamsRecipient tests the creation
// and validation of the original Honeycomb MSTeams recipient
// and the new Honeycomb MSTeams Workflow recipient.
func TestAccHoneycombMSTeamsRecipient(t *testing.T) {
t.Run("workflow recipient works", func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ProtoV5ProviderFactories: testAccProtoV5ProviderFactory,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "honeycombio_msteams_workflow_recipient" "test" {
name = "%s"
url = "https://example.com"
}`, test.RandomStringWithPrefix("test.", 10)),
},
},
})
})

t.Run("new webhook recipient fails creation", func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ProtoV5ProviderFactories: testAccProtoV5ProviderFactory,
Steps: []resource.TestStep{
{
Config: `
resource "honeycombio_msteams_recipient" "test" {
name = "test"
url = "https://example.com"
}`,
ExpectError: regexp.MustCompile(`Creating new MSTeams recipients is no longer possible`),
},
},
})
})
}
16 changes: 14 additions & 2 deletions honeycombio/resource_msteams_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
)

// Deprecated: MSTeams Recipient is deprecated, and does not allow creation of new recipients.
func newMSTeamsRecipient() *schema.Resource {
return &schema.Resource{
CreateContext: resourceMSTeamsRecipientCreate,
Expand All @@ -19,13 +20,16 @@ func newMSTeamsRecipient() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
DeprecationMessage: "MSTeams Recipient is deprecated. " +
"Creating new MSTeams recipients is no longer possible." +
"Please use the `honeycombio_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 All @@ -38,14 +42,22 @@ func newMSTeamsRecipient() *schema.Resource {
}

func resourceMSTeamsRecipientCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return createRecipient(ctx, d, meta, honeycombio.RecipientTypeMSTeams)
return diag.Diagnostics{diag.Diagnostic{
Severity: diag.Error,
Summary: "Creating new MSTeams recipients is no longer possible.",
Detail: "Microsoft has deprecated the Incoming Webhook feature, and as a result, " +
" we are no longer able to create new MSTeams recipients. " +
"Use the `honeycombio_msteams_workflow_recipient` resource instead.",
}}
}

func resourceMSTeamsRecipientRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
//nolint:staticcheck
return readRecipient(ctx, d, meta, honeycombio.RecipientTypeMSTeams)
}

func resourceMSTeamsRecipientUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
//nolint:staticcheck
return updateRecipient(ctx, d, meta, honeycombio.RecipientTypeMSTeams)
}

Expand Down
Loading

0 comments on commit 2806e22

Please sign in to comment.