diff --git a/docs/resources/notification_destination.md b/docs/resources/notification_destination.md new file mode 100644 index 0000000000..85f17fffa8 --- /dev/null +++ b/docs/resources/notification_destination.md @@ -0,0 +1,99 @@ +--- +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 be one of the following: + * `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. + diff --git a/internal/acceptance/notification_destination_test.go b/internal/acceptance/notification_destination_test.go index a1df5d3376..c466a833e7 100644 --- a/internal/acceptance/notification_destination_test.go +++ b/internal/acceptance/notification_destination_test.go @@ -1,16 +1,22 @@ 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 TestAccNDEmail(t *testing.T) { + display_name := "Email Notification Destination - " + qa.RandomName() workspaceLevel(t, step{ Template: ` resource "databricks_notification_destination" "this" { - display_name = "Email Notification Destination" + display_name = "` + display_name + `" config { email { addresses = ["` + qa.RandomEmail() + `"] @@ -18,5 +24,21 @@ func TestAccNDEmail(t *testing.T) { } } `, + Check: resourceCheck("databricks_notification_destination.this", func(ctx context.Context, client *common.DatabricksClient, id string) 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, settings.DestinationType("EMAIL"), ndResource.DestinationType) + assert.Equal(t, display_name, ndResource.DisplayName) + require.NoError(t, err) + return nil + }), }) } diff --git a/settings/resource_notification_destination.go b/settings/resource_notification_destination.go index cebb5967ef..8137c003f8 100644 --- a/settings/resource_notification_destination.go +++ b/settings/resource_notification_destination.go @@ -15,7 +15,6 @@ type NDStruct struct { func (NDStruct) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { // Required fields s.SchemaPath("display_name").SetRequired() - // s.SchemaPath("config").SetRequired() // Computed fields s.SchemaPath("id").SetComputed() @@ -45,13 +44,6 @@ func (NDStruct) CustomizeSchema(s *common.CustomizableSchema) *common.Customizab s.SchemaPath("config", "generic_webhook").SetRequiredWith([]string{"config.0.generic_webhook.0.url"}) s.SchemaPath("config", "email").SetRequiredWith([]string{"config.0.email.0.addresses"}) - // s.SchemaPath("config", "slack", "url").SetRequiredWith([]string{"config.0.slack"}) - // s.SchemaPath("config", "pagerduty", "integration_key").SetRequiredWith([]string{"config.0.pagerduty"}) - // s.SchemaPath("config", "microsoft_teams", "url").SetRequiredWith([]string{"config.0.microsoft_teams"}) - // s.SchemaPath("config", "generic_webhook", "url").SetRequiredWith([]string{"config.0.generic_webhook"}) - // s.SchemaPath("config", "generic_webhook", "password").SetRequiredWith([]string{"config.0.generic_webhook"}) - // s.SchemaPath("config", "email", "addresses").SetRequiredWith([]string{"config.0.email"}) - // Sensitive fields s.SchemaPath("config", "generic_webhook", "password").SetSensitive()