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
241 stars 169 forks source link

[Bug]: Removing mongodbatlas_alert_configuration resource block after Alert was deleted manually in UI results in 401 Unauthorized Error in Subsequent Plan #2264

Closed l-alfaro closed 4 months ago

l-alfaro commented 4 months ago

Is there an existing issue for this?

Provider Version

v1.16.0

Terraform Version

v1.6.2 (OpenTofu)

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

We are getting the following error in our plans after removing the alert configuration to address a drift result:

│ Error: error getting Alert Configuration information: %s
│ 
│ https://cloud.mongodb.com/api/atlas/v2/groups/xxxxxxxxxxxxxxx/alertConfigs/xxxxxxxxxxxxxxxxxxxx
│ GET: HTTP 401 Unauthorized (Error code: "") Detail: You are not authorized
│ for this resource. Reason: Unauthorized. Params: []

The removal of the resource is the only change being made. Adding it back results in the plan succeeding again.

Terraform configuration to reproduce the issue

resource "mongodbatlas_alert_configuration" "alert_5" {
  enabled    = true
  event_type = "OUTSIDE_METRIC_THRESHOLD"
  project_id = data.mongodbatlas_project.project.id
  metric_threshold_config {
    metric_name = "DISK_PARTITION_UTILIZATION_DATA"
    mode        = "AVERAGE"
    operator    = "GREATER_THAN"
    threshold   = 90
    units       = "RAW"
  }
  notification {
    api_token                   = null # sensitive
    channel_name                = null
    datadog_api_key             = null # sensitive
    datadog_region              = null
    delay_min                   = 0
    email_address               = null
    email_enabled               = true
    interval_min                = 60
    microsoft_teams_webhook_url = null # sensitive
    mobile_number               = null
    notifier_id                 = "xxxxxxxxxxxxxxxxxxxx"
    ops_genie_api_key           = null # sensitive
    ops_genie_region            = null
    roles                       = ["GROUP_OWNER"]
    service_key                 = null # sensitive
    sms_enabled                 = false
    team_id                     = null
    type_name                   = "GROUP"
    username                    = null
    victor_ops_api_key          = null # sensitive
    victor_ops_routing_key      = null # sensitive
    webhook_secret              = null # sensitive
    webhook_url                 = null # sensitive
  }
}

Steps To Reproduce

  1. Delete alert from Cloud UI
  2. Run a new plan. Notice a new resource will be added for the alert
  3. Delete mongodbatlas_alert_configuration resource block form TF code
  4. Run a new plan. Notice 401 error and failed plan

Logs

No response

Code of Conduct

github-actions[bot] commented 4 months 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-248530 was created for internal tracking.

github-actions[bot] commented 4 months ago

This issue has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

marcosuma commented 4 months ago

Hi @l-alfaro thanks for opening this issue with us. Just so I understand correctly: is this error happening when you are trying to delete the alert configuration from the TF script? Was that same alert configuration created through TF as well?

What the error is indicating is that it might be that you used different keys to create these alerts. I haven't tried to replicate locally, I'll wait for more updates before trying

github-actions[bot] commented 4 months ago

This issue has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!