mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
230 stars 167 forks source link

[Bug]: Unable to add a Slack alert notification without a key #2305

Closed waisbrot closed 1 month ago

waisbrot commented 1 month ago

Is there an existing issue for this?

Provider Version

1.16.0

Terraform Version

v1.5.7

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

Documentation bug: docs are either unclear or suggest something impossible

I'd like to be able to add notifications to Slack using Terraform.

In the alert configuration docs there's an api_token which, as far as I can tell, is required. But this token is generated by clicking through the Slack integration, and I haven't been able to retrieve it.

Is there some other way to get an API token for use in notifications? Or is it not possible to create Slack notifications under Terraform?

Terraform configuration to reproduce the issue

resource "mongodbatlas_alert_configuration" "example" {
  project_id = data.mongodbatlas_project.example.id
  event_type = "JOINED_GROUP"
  enabled    = true

  notification {
    email_enabled   = false
    type_name       = "SLACK"
    api_token       = ""
  }
}

Steps To Reproduce

  1. Connect Slack to an Atlas project
  2. Desire to manage Slack notifications via Terraform
  3. Unable to produce valid Terraform code because of the lack of a valid api_token

Logs

No response

Code of Conduct

github-actions[bot] commented 1 month ago

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

The ticket CLOUDP-250734 was created for internal tracking.

AgustinBettati commented 1 month ago

Hello @waisbrot.

this token is generated by clicking through the Slack integration, and I haven't been able to retrieve it.

There is a way of using credentials from a third party integration, which is what I believe you are referring to here. The following example shows how this can be done making use of integration_id. Note that the slack third party integration resource currently cannot be configured programatically as noted in our docs, but you can configure it in the UI and the use the third party integration data source to get the id as shown in the example.

Let me know if this is helpful for your use case.

waisbrot commented 1 month ago

Thanks. This did solve my problem.

I was confused because I believe the integration_id from manually-added integrations was different from alert to alert and because the error when you don't provide it at all is that api_token is required. I'll think about a PR to make the documentation spell it out a bit more.