newrelic / terraform-provider-newrelic

Terraform provider for New Relic
https://registry.terraform.io/providers/newrelic/newrelic/latest/docs
Mozilla Public License 2.0
200 stars 244 forks source link

fix(dashboards): fix broken condition when thresholds are nil with billboard widgets #2676

Closed pranav-new-relic closed 1 month ago

pranav-new-relic commented 1 month ago

Fixes #2675 (fixes a mishandled condition in #2672)


Summary

It has been reported via #2675 that (with the latest release of the provider, v3.37.0) running a terraform plan on configuration comprising of widget_billboard in the resource newrelic_one_dashboard is running into panic, and is hence, failing.

Steps to Reproduce

resource "newrelic_one_dashboard" "exampledash" {
  name        = "THRESHOLD TEST DASHBOARD"
  permissions = "public_read_only"

  page {

    name = "New Relic Terraform Example"
    widget_billboard {
      title  = "Billboard Widget 1"
      row    = 1
      column = 1
      width  = 4
      height = 4

      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }
    }

    widget_billboard {
      title  = "Billboard Widget 2"
      row    = 5
      column = 1
      width  = 4
      height = 3

      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }

      critical = "300"
      warning  = "500"
    }
  }
}

The Fix

Based on the observation made above, it appears that the absence of a condition to handle the case when the Thresholds attribute of the dashboard's RawConfiguration is nil (only in the case of billboard widgets) is leading to this failure; adding a relevant condition should fix the problem, which is what this PR aims at doing.

pranav-new-relic commented 1 month ago

Merging this PR as the change made has been thoroughly tested manually (with the steps documented above), and no failures are seen in relevant integration tests.