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
244 stars 172 forks source link

email_enabled always reported as a change for mongodbatlas_alert_configuration #306

Closed MartinCanovas closed 4 years ago

MartinCanovas commented 4 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v0.12.26
+ provider.mongodbatlas v0.6.4

Terraform Configuration File

resource "mongodbatlas_alert_configuration" "alert1" {
  project_id = var.project_id
  event_type = "OUTSIDE_METRIC_THRESHOLD"
  enabled    = true

  notification {
    type_name     = "EMAIL"
    interval_min  = 5
    delay_min     = 0
    sms_enabled   = false
    email_enabled = true
    email_address = var.email_address
  }

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

  metric_threshold = {
    metric_name = "ASSERT_REGULAR"
    operator    = "GREATER_THAN"
    threshold   = 70.0
    units       = "RAW"
    mode        = "AVERAGE"
  }
}

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. Alert is created without issues. However next time you run terraform apply without any changes on the code, terraform will report in the Plan a change for the alert configuration:

~ notification { delay_min = 0 email_address = "xxxxxxxxxxx" ~ email_enabled = false -> true interval_min = 5 roles = [] sms_enabled = false type_name = "EMAIL" } Plan: 0 to add, 1 to change, 0 to destroy.

Expected Behavior

Plan: 0 to add, 0 to change, 0 to destroy. ### Actual Behavior Plan: 0 to add, 1 to change, 0 to destroy. ### Debug Output

Crash Output

Additional Context

References

MartinCanovas commented 4 years ago

debug.log

themantissa commented 4 years ago

Thank you @MartinCanovas! We'll add this to the list to address.

nikhil-mongo commented 4 years ago

@MartinCanovas As per the notifications.[n].emailEnabled section of the Atlas API email_enabled =true is only required in case the notification type is GROUP, ORG, or USER. This is why the terraform.tfstate file stores this value as email_enabled =false. When you run plan and the state file refreshes with the real-world and configuration does not matches and thus it shows you the plan changes.

Therefore, the correct terraform config would be -

resource "mongodbatlas_alert_configuration" "alert1" {
  project_id = var.project_id
  event_type = "OUTSIDE_METRIC_THRESHOLD"
  enabled    = true

  notification {
    type_name     = "EMAIL"
    interval_min  = 5
    delay_min     = 0
    sms_enabled   = false
    email_address = var.email_address
  }

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

  metric_threshold = {
    metric_name = "ASSERT_REGULAR"
    operator    = "GREATER_THAN"
    threshold   = 70.0
    units       = "RAW"
    mode        = "AVERAGE"
  }
}

This way terraform plan will not show changes everytime and thus this issue can be closed as it is not a bug.

MartinCanovas commented 4 years ago

@nikhil-mongo Excellent! Thanks for clarifying that, and my apologies for reporting this as a bug when it isn't.

themantissa commented 4 years ago

Good catch @nikhil-mongo - I'll close this since resolved.