BetterStackHQ/terraform-provider-better-uptime

Maintenance Days always being reset

Closed this issue · 6 comments

Recently, I've noticed that when doing Terraform updates the maintenance days are always being reset as below. This happens every time I apply our Terraform plan, without touching the betteruptime_monitor resource in the plan

  ~ resource "betteruptime_monitor" "frontend" {
        id                    = "XXXXXXX"
      ~ maintenance_days      = [
          - "mon",
          - "tue",
          - "wed",
          - "thu",
          - "fri",
          - "sat",
          - "sun",
        ]
        # (39 unchanged attributes hidden)
    }

I believe this is happening because the Terraform provider has maintenance_days to be an empty list, but when applied to the API the API must convert an empty list to a list containing all the elements. As such:

sequenceDiagram
    note left of Terraform State: Resource has maintenance_days = []
    Terraform State->>+BetterStack API: apply maintenance_days = []
    note right of BetterStack API: maintenace_days = [mon, tues, wed, ...]
    loop Every time the Terraform plan is applied
    BetterStack API->>+Terraform State: Retrieve state  maintenace_days = [mon, tues, wed, ...]
    note left of Terraform State: Check state against resource
    note left of Terraform State: State doesn't match resource, applying
    Terraform State->>+BetterStack API: apply maintenance_days = []
    note right of BetterStack API: maintenace_days = [mon, tues, wed, ...]
    end
Loading

This happens with resource code as below:

resource "betteruptime_monitor" "frontend" {
  url              = "https://${var.frontend_domain_name}"
  monitor_type     = "status"
  monitor_group_id = betteruptime_monitor_group.group.id

  provider = better-uptime
}

I believe a workaround is to use the following, although it seems very confusing:

maintenance_days = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]

I believe a workaround is to use the following, although it seems very confusing:

maintenance_days = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]

Yeah I can confirm this works as a workaround - but really you shouldn't need to specify that as it's marked as optional

I escalated this via support, received confirmation they will fix it.

Thanks for reporting it in such a detail 🙌

Specifying the field as Optional and Computed will make sure the API-returned values are always respected. I've proposed a fix in #96 and the issue should be addressed in v0.10.0.

Thanks for reporting it in such a detail 🙌

Specifying the field as Optional and Computed will make sure the API-returned values are always respected. I've proposed a fix in #96 and the issue should be addressed in v0.10.0.

Thank you!

Just released v0.10.0 which fixes the issue with optional field being reset 🙌