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

[Bug]: mongodbatlas_maintenance_window changes every time #2410

Closed icco closed 1 month ago

icco commented 2 months ago

Is there an existing issue for this?

Provider Version

v1.17.3

Terraform Version

v1.5.3

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

Every plan and apply we run the maintence windows change, even though the code hasn't changed at all.

  # module.atlas_project.mongodbatlas_maintenance_window.this["fri"] will be updated in-place
  ~ resource "mongodbatlas_maintenance_window" "this" {
      ~ day_of_week             = 1 -> 6
        id                      = "63c76c38b4933e38a7c081f4"
        # (5 unchanged attributes hidden)
    }

  # module.atlas_project.mongodbatlas_maintenance_window.this["mon"] will be updated in-place
  ~ resource "mongodbatlas_maintenance_window" "this" {
      ~ day_of_week             = 1 -> 2
        id                      = "63c76c38b4933e38a7c081f4"
        # (5 unchanged attributes hidden)
    }

  # module.atlas_project.mongodbatlas_maintenance_window.this["sat"] will be updated in-place
  ~ resource "mongodbatlas_maintenance_window" "this" {
      ~ day_of_week             = 1 -> 7
      ~ hour_of_day             = 0 -> 16
        id                      = "63c76c38b4933e38a7c081f4"
        # (4 unchanged attributes hidden)
    }

  # module.atlas_project.mongodbatlas_maintenance_window.this["sun"] will be updated in-place
  ~ resource "mongodbatlas_maintenance_window" "this" {
      ~ hour_of_day             = 0 -> 16
        id                      = "63c76c38b4933e38a7c081f4"
        # (5 unchanged attributes hidden)
    }

  # module.atlas_project.mongodbatlas_maintenance_window.this["thu"] will be updated in-place
  ~ resource "mongodbatlas_maintenance_window" "this" {
      ~ day_of_week             = 1 -> 5
        id                      = "63c76c38b4933e38a7c081f4"
        # (5 unchanged attributes hidden)
    }

  # module.atlas_project.mongodbatlas_maintenance_window.this["tue"] will be updated in-place
  ~ resource "mongodbatlas_maintenance_window" "this" {
      ~ day_of_week             = 1 -> 3
        id                      = "63c76c38b4933e38a7c081f4"
        # (5 unchanged attributes hidden)
    }

Terraform configuration to reproduce the issue

locals {
  # On weekdays, midnight UTC (so no one is working)
  # On weekends, 4p UTC (so folks are awake in PT)
  windows = {
    "mon" = { day = 2, hour = 0 },
    "tue" = { day = 3, hour = 0 },
    "wed" = { day = 4, hour = 0 },
    "thu" = { day = 5, hour = 0 },
    "fri" = { day = 6, hour = 0 },
    "sat" = { day = 7, hour = 16 },
    "sun" = { day = 1, hour = 16 },
  }
}

resource "mongodbatlas_maintenance_window" "this" {
  for_each = local.windows

  project_id = resource.mongodbatlas_project.project.id

  day_of_week = each.value.day
  hour_of_day = each.value.hour
}

Steps To Reproduce

  1. create a project (resource.mongodbatlas_project.project)
  2. apply the attached config
  3. apply it again and see that it changes the windows every time

Logs

No response

Code of Conduct

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

AgustinBettati commented 1 month ago

Hi @icco, thank you for raising the ticket.

The main issue with the configuration shared above is that there are multiple mongodbatlas_maintenance_window resources defined for the same project, which is not the intended use case. Only a single maintenance window configuration is expected to be defined per project. From the Maintenance Window documentation you will see that automated maintenance runs on a weekly basis, giving users the flexibility to define at which day and hour it is run.

Opened a PR so we clarify this in our mongodbatlas_maintenance_window resource documentation: https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2418.

icco commented 1 month ago

Fascinating. Thank you. I kind of wish the backend would throw an error, given it looks like each window has a unique ID.