Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Notification Destination resource #3820

Merged
merged 23 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ff7fdd1
WIP
Divyansh-db Jul 24, 2024
5735002
Merge branch 'main' into divyansh_notification_destinations
Divyansh-db Jul 24, 2024
209487e
Made Notification Destination resource
Divyansh-db Jul 25, 2024
36f845e
added some sensitive fields
Divyansh-db Jul 25, 2024
e7b7381
added documentation and improved integration test
Divyansh-db Jul 25, 2024
3a2efbd
wip
Divyansh-db Jul 26, 2024
2a9d9f3
Update docs/resources/notification_destination.md
Divyansh-db Jul 26, 2024
a7a5086
Merge branch 'Divyansh-db/divyansh_notification_destinations' of gith…
Divyansh-db Jul 26, 2024
2eb0d15
wip
Divyansh-db Jul 29, 2024
7f5de75
Fixed the resource and added integration tests for all fields
Divyansh-db Jul 29, 2024
17b0463
fixed the resource code
Divyansh-db Jul 29, 2024
726b346
Added support for changing Destination type
Divyansh-db Jul 29, 2024
0a97a21
Merge branch 'main' into Divyansh-db/divyansh_notification_destinations
Divyansh-db Jul 29, 2024
80c1d59
wip
Divyansh-db Jul 31, 2024
adc6f7b
modified doc for notification destination
Divyansh-db Jul 31, 2024
1cd8f71
merged main
Divyansh-db Jul 31, 2024
ea6ceb5
added force send fields
Divyansh-db Jul 31, 2024
db3f2ea
Merge branch 'main' into Divyansh-db/divyansh_notification_destinations
Divyansh-db Jul 31, 2024
ae1c4f1
fixed a unit test
Divyansh-db Jul 31, 2024
85441c7
Merge branch 'Divyansh-db/divyansh_notification_destinations' of gith…
Divyansh-db Jul 31, 2024
44ce52d
Merge branch 'main' into Divyansh-db/divyansh_notification_destinations
Divyansh-db Jul 31, 2024
cc9cc4d
modified docs and integration tests
Divyansh-db Aug 1, 2024
78f0434
Merge branch 'Divyansh-db/divyansh_notification_destinations' of gith…
Divyansh-db Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions docs/resources/notification_destination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
subcategory: "Workspace"
---
# databricks_notification_destination Resource

This resource allows you to manage [Notification Destinations](https://docs.databricks.com/api/workspace/notificationdestinations). Notification destinations are used to send notifications for query alerts and jobs to destinations outside of Databricks. Only workspace admins can create, update, and delete notification destinations.

## Example Usage

`Email` notification destination:

```hcl
resource "databricks_notification_destination" "ndresource" {
display_name = "Notification Destination"
config {
email {
addresses = ["abc@gmail.com"]
}
}
}
```
`Slack` notification destination:

```hcl
resource "databricks_notification_destination" "ndresource" {
display_name = "Notification Destination"
config {
slack {
url = "https://hooks.slack.com/services/..."
}
}
}
```
`PagerDuty` notification destination:

```hcl
resource "databricks_notification_destination" "ndresource" {
display_name = "Notification Destination"
config {
pagerduty {
integration_key = "xxxxxx"
}
}
}
```
`Microsoft Teams` notification destination:

```hcl
resource "databricks_notification_destination" "ndresource" {
display_name = "Notification Destination"
config {
microsoft_teams {
url = "https://outlook.office.com/webhook/..."
}
}
}
```
`Generic Webhook` notification destination:

```hcl
resource "databricks_notification_destination" "ndresource" {
display_name = "Notification Destination"
config {
generic_webhook {
url = "https://example.com/webhook"
username = "username" // Optional
password = "password" // Optional
}
}
}
```


## Argument Reference

The following arguments are supported:

* `display_name` - (Required) The display name of the Notification Destination.
* `config` - (Required) The configuration of the Notification Destination. It must contain exactly one of the following blocks:
* `email` - The email configuration of the Notification Destination. It must contain the following:
* `addresses` - (Required) The list of email addresses to send notifications to.
* `slack` - The Slack configuration of the Notification Destination. It must contain the following:
* `url` - (Required) The Slack webhook URL.
* `pagerduty` - The PagerDuty configuration of the Notification Destination. It must contain the following:
* `integration_key` - (Required) The PagerDuty integration key.
* `microsoft_teams` - The Microsoft Teams configuration of the Notification Destination. It must contain the following:
* `url` - (Required) The Microsoft Teams webhook URL.
* `generic_webhook` - The Generic Webhook configuration of the Notification Destination. It must contain the following:
* `url` - (Required) The Generic Webhook URL.
* `username` - (Optional) The username for basic authentication.
* `password` - (Optional) The password for basic authentication.


## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The unique ID of the Notification Destination.


## Note
* If the type of notification destination is changed, the existing notification destination will be deleted and a new notification destination will be created with the new type.
Divyansh-db marked this conversation as resolved.
Show resolved Hide resolved
217 changes: 217 additions & 0 deletions internal/acceptance/notification_destination_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package acceptance

import (
"context"
"testing"

"github.com/databricks/databricks-sdk-go/service/settings"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/qa"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func check(t *testing.T, ctx context.Context, client *common.DatabricksClient, id, display_name string, config_type settings.DestinationType) error {
w, err := client.WorkspaceClient()
if err != nil {
return err
}
ndResource, err := w.NotificationDestinations.Get(ctx, settings.GetNotificationDestinationRequest{
Id: id,
})
if err != nil {
return err
}
assert.Equal(t, config_type, ndResource.DestinationType)
assert.Equal(t, display_name, ndResource.DisplayName)
require.NoError(t, err)
return nil
}
Divyansh-db marked this conversation as resolved.
Show resolved Hide resolved

func TestAccNDEmail(t *testing.T) {
display_name := "Email Notification Destination - " + qa.RandomName()
workspaceLevel(t, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
email {
addresses = ["` + qa.RandomEmail() + `"]
}
}
Divyansh-db marked this conversation as resolved.
Show resolved Hide resolved
}
`,
}, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
email {
addresses = ["` + qa.RandomEmail() + `", "` + qa.RandomEmail() + `"]
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeEmail)
}),
})
}

func TestAccNDSlack(t *testing.T) {
display_name := "Notification Destination - " + qa.RandomName()
workspaceLevel(t, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
slack {
url = "https://hooks.slack.com/services/{var.RANDOM}"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeSlack)
}),
}, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
slack {
url = "https://hooks.slack.com/services/{var.RANDOM}"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeSlack)
}),
})
}

func TestAccNDMicrosoftTeams(t *testing.T) {
display_name := "Notification Destination - " + qa.RandomName()
workspaceLevel(t, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
microsoft_teams {
url = "https://outlook.office.com/webhook/{var.RANDOM}"
}
}
}
`,
}, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
microsoft_teams {
url = "https://outlook.office.com/webhook/{var.RANDOM}"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeMicrosoftTeams)
}),
})
}

func TestAccNDPagerduty(t *testing.T) {
display_name := "Notification Destination - " + qa.RandomName()
workspaceLevel(t, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
pagerduty {
integration_key = "{var.RANDOM}"
}
}
}
`,
}, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
pagerduty {
integration_key = "{var.RANDOM}"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypePagerduty)
}),
})
}

func TestAccNDGenericWebhook(t *testing.T) {
display_name := "Notification Destination - " + qa.RandomName()
workspaceLevel(t, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
generic_webhook {
url = "https://webhook.site/{var.RANDOM}"
password = "password"
}
}
}
`,
}, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
generic_webhook {
url = "https://webhook.site/{var.RANDOM}"
username = "username2"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeWebhook)
}),
})
}

func TestAccConfigTypeChange(t *testing.T) {
display_name := "Notification Destination - " + qa.RandomName()
workspaceLevel(t, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
slack {
url = "https://hooks.slack.com/services/{var.RANDOM}"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeSlack)
}),
}, step{
Template: `
resource "databricks_notification_destination" "this" {
display_name = "` + display_name + `"
config {
microsoft_teams {
url = "https://outlook.office.com/webhook/{var.RANDOM}"
}
}
}
`,
Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
return check(t, ctx, client, id, display_name, settings.DestinationTypeMicrosoftTeams)
}),
})
}
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func DatabricksProvider() *schema.Provider {
"databricks_mws_vpc_endpoint": mws.ResourceMwsVpcEndpoint().ToResource(),
"databricks_mws_workspaces": mws.ResourceMwsWorkspaces().ToResource(),
"databricks_notebook": workspace.ResourceNotebook().ToResource(),
"databricks_notification_destination": settings.ResourceNotificationDestination().ToResource(),
"databricks_obo_token": tokens.ResourceOboToken().ToResource(),
"databricks_online_table": catalog.ResourceOnlineTable().ToResource(),
"databricks_permission_assignment": access.ResourcePermissionAssignment().ToResource(),
Expand Down
Loading
Loading