appoptics / terraform-provider-appoptics

Apache License 2.0
4 stars 2 forks source link

Refreshed state shows attributes for metric created without attributes #53

Open poleszcz opened 1 year ago

poleszcz commented 1 year ago

Metric is created as

resource appoptics_metric metric_one {
  name = "example.metric_one"
  type = "gauge"
}

When you run *terraform plan" without any local changes, the response contains attributes that our new plan want to remove (but we didn't define them !)

appoptics_metric.metric_one: Refreshing state... [id=example.metric_one]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # appoptics_metric.metric_one will be updated in-place
  ~ resource "appoptics_metric" "metric_one" {
        id   = "example.metric_one"
        name = "example.metric_one"
        # (1 unchanged attribute hidden)

      - attributes {
          - aggregate       = false -> null
          - created_by_ua   = "appoptics-api-go" -> null
          - display_max     = 0 -> null
          - display_min     = 0 -> null
          - display_stacked = false -> null
          - gap_detection   = false -> null
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

If you try *terraform apply" then plugin crashes

appoptics_metric.metric_one: Modifying... [id=example.metric_one]
╷
│ Error: Plugin did not respond
│
│   with appoptics_metric.metric_one,
│   on metric.tf line 1, in resource "appoptics_metric" "metric_one":
│    1: resource appoptics_metric metric_one {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-appoptics plugin:

panic: runtime error: index out of range [0] with length 0

goroutine 16 [running]:
github.com/appoptics/terraform-provider-appoptics/appoptics.resourceAppOpticsMetricUpdate(0xc000180850, {0x557c99fded80?, 0xc00018a000})
        github.com/appoptics/terraform-provider-appoptics/appoptics/resource_appoptics_metric.go:257 +0xca5
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc00019c880, 0xc000100f50, 0xc0000dc620, {0x557c99fded80, 0xc00018a000})
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/helper/schema/resource.go:311 +0x3e3
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc00019ce80, 0xc0003c7990, 0x557c99aecdcd?, 0xf?)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/helper/schema/provider.go:294 +0x70
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc00011c740, {0xc00035c900?, 0x557c99396586?}, 0xc00035c900)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/internal/helper/plugin/grpc_provider.go:885 +0x7c5
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x557c99feb400?, 0xc00011c740}, {0x557c9a023818, 0xc0000baa20}, 0xc00035c8a0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/internal/tfplugin5/tfplugin5.pb.go:3189 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000550540, {0x557c9a026d08, 0xc00027a000}, 0xc000196800, 0xc000577560, 0x557c9a55cd80, 0x0)
        google.golang.org/grpc@v1.31.0/server.go:1180 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc000550540, {0x557c9a026d08, 0xc00027a000}, 0xc000196800, 0x0)
        google.golang.org/grpc@v1.31.0/server.go:1503 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.31.0/server.go:843 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.31.0/server.go:841 +0x28a

Error: The terraform-provider-appoptics plugin crashed!