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
242 stars 168 forks source link

mongodbatlas_alert_configuration failing to be created on apply due to `METRIC_TYPE_UNSUPPORTED` 400 error #1242

Closed omarfakhreddine closed 1 year ago

omarfakhreddine commented 1 year ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

terraform {
  required_version = ">= 1.0"
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "~> 1.9"
    }
  }
}

Terraform cloud workspace version: v1.5.0 MongoDB Atlas Provider Version: v1.9.0

Terraform Configuration File

resource "mongodbatlas_alert_configuration" "replication_lag_alert" {
  for_each = toset([for project in module.projects : project.id])

  project_id = each.key
  enabled    = true
  event_type = "OUTSIDE_METRIC_THRESHOLD"

  notification {
    type_name         = "OPS_GENIE"
    delay_min         = 10
    ops_genie_api_key = data.vault_generic_secret.opsgenie_api_key.data["api-key"]
  }

  matcher {
    field_name = "TYPE_NAME"
    operator   = "EQUALS"
    value      = "SECONDARY"
  }

  metric_threshold_config {
    metric_name = "OPLOG_REPLICATION_LAG_TIME"
    operator    = "GREATER_THAN"
    threshold   = 10
    units       = "SECONDS"
    mode        = "AVERAGE"
  }
}

Steps to Reproduce

  1. Merge PR with the alert configuration change
  2. That triggers a plan in the TFC workspace
  3. Manually confirm the apply in the TFC run through the UI

Expected Behavior

After applying the planned change in TFC, the run apply will succeed and create the alert in the Atlas projects

Actual Behavior

The run apply fails and returns Error: error creating Alert Configuration

Debug Output

---[ REQUEST ]---------------------------------------
POST /api/atlas/v1.0/groups/64477cd521100e59b34daa43/alertConfigs HTTP/1.1
Host: cloud.mongodb.com
User-Agent: terraform-provider-mongodbatlas/1.9.0 go-mongodbatlas/0.25.0 (linux;amd64)
Content-Length: 430
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

{
 "eventTypeName": "OUTSIDE_METRIC_THRESHOLD",
 "enabled": true,
 "matchers": [
  {
   "fieldName": "TYPE_NAME",
   "operator": "EQUALS",
   "value": "SECONDARY"
  }
 ],
 "metricThreshold": {
  "metricName": "OPLOG_REPLICATION_LAG_TIME",
  "operator": "GREATER_THAN",
  "threshold": 10,
  "units": "SECONDS",
  "mode": "AVERAGE"
 },
 "notifications": [
  {
   "delayMin": 10,
   "emailEnabled": false,
   "opsGenieApiKey": "***************************************************",
   "smsEnabled": false,
   "typeName": "OPS_GENIE"
  }
 ]
}

-----------------------------------------------------: timestamp=2023-06-15T17:05:53.974Z
2023-06-15T17:05:54.033Z [INFO]  provider.terraform-provider-mongodbatlas_v1.9.0: 2023/06/15 17:05:54 [DEBUG] MongoDB Atlas API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 400 Bad Request
Content-Length: 190
Content-Type: application/json
Date: Thu, 15 Jun 2023 17:05:53 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: mdbws
Strict-Transport-Security: max-age=31536000; includeSubdomains;
X-Content-Type-Options: nosniff
X-Envoy-Upstream-Service-Time: 38
X-Frame-Options: DENY
X-Mongodb-Service-Version: gitHash=e40c18c00495d1a1246db51b5e49eb00a8348a43; versionString=v20230614
X-Permitted-Cross-Domain-Policies: none

{
 "detail": "The metric type OPLOG_REPLICATION_LAG_TIME is not supported.",
 "error": 400,
 "errorCode": "METRIC_TYPE_UNSUPPORTED",
 "parameters": [
  "OPLOG_REPLICATION_LAG_TIME"
 ],
 "reason": "Bad Request"
}
-----------------------------------------------------: timestamp=2023-06-15T17:05:54.033Z

Additional Context

The metric name should be correct based on the Atlas API docs image

github-actions[bot] commented 1 year ago

Thanks for opening this issue. The ticket INTMDB-872 was created for internal tracking.

maastha commented 1 year ago

Hi @omarfakhreddine

We are unable to allow OPLOG_REPLICATION_LAG_TIME metric to be setup in this context. Verified internally that this should be excluded from the documentation. We are working on removing this metric from Atlas API documentation and can be tracked via internal ticket CLOUDP-185612.

omarfakhreddine commented 1 year ago

Thank you @maastha

Does this mean I will need to manually configure this alert through the Atlas UI and I won't be able to import it using Terraform and manage it that way?

Zuhairahmed commented 1 year ago

@omarfakhreddine no you can still leverage Terraform for alert configuration, it is just that OPLOG_REPLICATION_LAG_TIME parameter is not available to leverage. hope this helps to clarify. feel free to open a new issue in case you need anything else. thank you.