dbt-labs / terraform-provider-dbtcloud

dbt Cloud Terraform Provider
https://registry.terraform.io/providers/dbt-labs/dbtcloud
MIT License
80 stars 18 forks source link

Expand notification resource to support Slack type #222

Closed katieclaiborne closed 7 months ago

katieclaiborne commented 7 months ago

Is your feature request related to a problem? Please describe.

I'm working to import dbt Cloud resources into our Terraform state, and would like to be able to include our Slack notifications.

Describe the solution you'd like

I'd like to be able to configure Slack notifications for a job as a resource.

I see an existing notification resource, but it appears to be specific to email notifications. Please correct me if I'm wrong here!

Describe alternatives you've considered

The documentation includes guidance for using the HTTP provider to retrieve data, but I figured I'd start by raising an issue.

Additional context

Based on the existing resource and the Create Notification endpoint, I think an example could look like:

resource "dbtcloud_notification" "slack" {
    user_id            = 12345
    slack_channel_id   = "A1234BC45DE"
    slack_channel_name = "#dbt-cloud-notifications"
    on_cancel          = [123456]
    on_failure         = [123456]
    on_success         = [123456]
    // the Type 2 is used for Slack notifications
    notification_type  = 2
}
will-sargent-dbtlabs commented 7 months ago

Hi Katie! I think this is a great suggestion for sure. Slack is tricky, because in our current backend code, a single admin-level user per account makes the connection to slack, and from there, all notifications are sent over that bridge.

I'm not saying it's impossible, it's just an additional layer of complexity involved, because for email we are self contained. For slack, we have to OAuth against slack initially to link dbt Cloud to your Slack account, before we can actually configure the notifications.

Likely this might require the configuration of two different terraform resources: Resource 1 for the connection itself (which is stored in one database table) Resource 2 for the notification configuration record (which is in a different table, but the same one as the email configs).

I'll let @b-per drop his thoughts in too, as this would be great to be able to do!

b-per commented 7 months ago

I can have a look yes, but I am not sure how easy it is. It definitely won't be easy or possible to set the Slack connection itself from Terraform, but we might be able to set the notifications, once the connection is configured correctly from the UI.

As a workaround, would you be able to use the ability to send emails to a specific address to get notifications sent to Slack? image

Sending notifications to external email addresses is already available in the Terraform provider.

katieclaiborne commented 7 months ago

Yes! I'll give it a look this week and report back.

katieclaiborne commented 7 months ago

I'm blocked on our Slack admins at the moment, but agree in principle that email notifications represent a workaround.

At the same time, I do still think the ability to configure Slack notifications in Terraform (assuming a manually pre-configured connection) is worth exploring.

b-per commented 7 months ago

I actually just added support for it in 0.2.17. It should be out soon.

katieclaiborne commented 7 months ago

That's so exciting! Thank you, Benoit.