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

Plugin crashed on v3.37.0 #2675

Closed a88zach closed 1 month ago

a88zach commented 1 month ago

Terraform Version

1.8.4

Affected Resource(s)

Terraform Configuration

locals {
  functions = {
    binbar_swap_detector = {
      display_name  = "BinBar swap detector"
      function_name = "binbar-swap-detector-main"
    }
    container_site_offline_detector = {
      display_name  = "Container site offline detector"
      function_name = "container-site-offline-detector-main"
    }
    installation_detector = {
      display_name  = "Installation detector"
      function_name = "installation-detector-main"
    }
    load_detector = {
      display_name  = "Load detector"
      function_name = "load-detector-main"
    }
    notification_generator = {
      display_name  = "Notification generator"
      function_name = "notification-generator-main"
    }
    notification_processor = {
      display_name  = "Notification processor"
      function_name = "notification-processor-main"
    }
    particle_webhook = {
      display_name  = "Particle webhook"
      function_name = "particle-webhook-main"
    }
    removal_detector = {
      display_name  = "Removal detector"
      function_name = "removal-detector-main"
    }
    waf_generator = {
      display_name  = "WAF generator"
      function_name = "waf-generator-main"
    }
    weight_ticket_processor = {
      display_name  = "Weight ticket processor"
      function_name = "weight-ticket-processor-main"
    }
  }
}

resource "newrelic_one_dashboard" "cloud_functions" {
  name        = "Cloud functions"
  permissions = "public_read_only"

  dynamic "page" {
    for_each = local.functions

    content {
      name = page.value.display_name

      widget_billboard {
        title  = "Error rate"
        row    = 1
        column = 1
        width  = 3
        height = 2

        nrql_query {
          query = "SELECT percentage(sum(`function.Executions`), WHERE `status` = 'error') from GcpCloudFunctionSample WHERE `entityName` = '${page.value.function_name}' AND `function.Executions` > 0"
        }
      }

      widget_bar {
        title  = "Execution count"
        row    = 1
        column = 4
        width  = 9
        height = 2

        nrql_query {
          query = "SELECT sum(`function.Executions`) FROM GcpCloudFunctionSample WHERE `entityName` = '${page.value.function_name}' FACET `displayName`"
        }
      }

      widget_log_table {
        title  = "Logs"
        row    = 2
        column = 1
        width  = 12
        height = 6

        nrql_query {
          query = "SELECT `message` FROM Log WHERE `resource.labels.function_name` = '${page.value.function_name}'"
        }
      }
    }
  }
}

resource "newrelic_one_dashboard" "cloud_run" {
  name        = "Cloud run"
  permissions = "public_read_only"

  page {
    name = "Client API"

    widget_log_table {
      title  = "Logs"
      row    = 1
      column = 1
      width  = 12
      height = 6

      nrql_query {
        query = "SELECT `message` FROM Log WHERE `entity.name` = 'client-api-main' OR `resource.labels.service_name` = 'client-api-main'"
      }
    }
  }
}

resource "newrelic_one_dashboard" "cloud_scheduler" {
  name        = "Cloud scheduler"
  permissions = "public_read_only"

  page {
    name = "Scheduler jobs"

    widget_log_table {
      title  = "Logs"
      row    = 1
      column = 1
      width  = 12
      height = 6

      nrql_query {
        query = "SELECT `resource.labels.job_id`,`httpRequest.status` FROM Log WHERE `resource.type` = 'cloud_scheduler_job'"
      }
    }
  }
}

Actual Behavior

Plugin crashes when creating a plan

Expected Behavior

Plugin should not crash

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan

Panic Output

Stack trace from the terraform-provider-newrelic_v3.37.0 plugin:

panic: interface conversion: interface {} is nil, not []interface {}

goroutine 226 [running]:
github.com/newrelic/terraform-provider-newrelic/v2/newrelic.flattenDashboardWidget(0xc000a2b0a8, {0xc0003ee1b0, 0x28})
/home/runner/work/terraform-provider-newrelic/terraform-provider-newrelic/newrelic/structures_newrelic_one_dashboard.go:1206 +0x2785
github.com/newrelic/terraform-provider-newrelic/v2/newrelic.flattenDashboardPage(0xc0004ef5f8)
/home/runner/work/terraform-provider-newrelic/terraform-provider-newrelic/newrelic/structures_newrelic_one_dashboard.go:1109 +0x350
github.com/newrelic/terraform-provider-newrelic/v2/newrelic.flattenDashboardEntity(0xc0004ef200, 0x111fed8?)
/home/runner/work/terraform-provider-newrelic/terraform-provider-newrelic/newrelic/structures_newrelic_one_dashboard.go:949 +0x19c
github.com/newrelic/terraform-provider-newrelic/v2/newrelic.resourceNewRelicOneDashboardRead({0x111fed8, 0xc0000ef490}, 0xc000656000, {0xe004c0?, 0xc0001765c0?})
/home/runner/work/terraform-provider-newrelic/terraform-provider-newrelic/newrelic/resource_newrelic_one_dashboard.go:840 +0x2fd
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc000497a40, {0x111fe30, 0xc000d031d0}, 0xd?, {0xe004c0, 0xc0001765c0})
/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:724 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000497a40, {0x111fe30, 0xc000d031d0}, 0xc00065c9c0, {0xe004c0, 0xc0001765c0})
/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:1015 +0x549
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0003ec030, {0x111fe30?, 0xc000d030e0?}, 0xc00001e500)
/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:613 +0x48a
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0003e2000, {0x111fe30?, 0xc000d02660?}, 0xc0008059e0)
/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:748 +0x48b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xf22700?, 0xc0003e2000}, {0x111fe30, 0xc000d02660}, 0xc000254bd0, 0x0)
/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002a01e0, {0x1124f18, 0xc000500ea0}, 0xc0008c4480, 0xc0005071d0, 0x17ae090, 0x0)
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.57.1/server.go:1358 +0xe15
google.golang.org/grpc.(*Server).handleStream(0xc0002a01e0, {0x1124f18, 0xc000500ea0}, 0xc0008c4480, 0x0)
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.57.1/server.go:1735 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.57.1/server.go:970 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 27
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.57.1/server.go:981 +0x145

Error: The terraform-provider-newrelic_v3.37.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Important Factoids

This was working with v3.36.1

pranav-new-relic commented 1 month ago

@a88zach @alexalaniswork we just released (few moments ago) a fix to this with v3.37.1 of the New Relic Terraform Provider; I've just pulled the new version and I am no longer able to reproduce the issue. Please upgrade to v3.37.1, give this a try and let me know what you see.

Thank you for reporting this :)

a88zach commented 1 month ago

@pranav-new-relic working as expected with version 3.37.1. Thanks for the quick turn around!