hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.58k stars 966 forks source link

panic: AttributeName("*"): can't use tftypes.DynamicPseudoType as tftypes.List #2052

Closed niklasember closed 1 year ago

niklasember commented 1 year ago

Terraform Version, Provider Version and Kubernetes Version

Terraform version: v1.4.2
Kubernetes provider version: v2.18.1
Kubernetes version: v1.26.1

Affected Resource(s)

kubernetes_manifest

Terraform Configuration Files

resource "kubernetes_manifest" "openebs_cstor_disk_pool_mirrored" {
  manifest = {
    "apiVersion" = "cstor.openebs.io/v1"
    "kind" = "CStorPoolCluster"
    "metadata" = {
      "name" = "cstor-disk-pool"
      "namespace" = "openebs"
    }
    "spec" = {
      "pools" = [
         for node, disk in local.disks_merged:
         {
           "dataRaidGroups" = [
             {
               "blockDevices" = [
                 for disk in disk[0]:
                 {
                   "blockDeviceName" = disk
                 }
               ]
             },
           ]
           "nodeSelector" = {
             "kubernetes.io/hostname" = node
           }
           "poolConfig" = {
             "dataRaidGroupType" = "mirror"
           }
         }
      ]
    }
  }
}

locals {
  disks = [
    for item in data.kubernetes_resources.openebs_blockstorage.objects:
    {disk: item.metadata.name, node: item.spec.nodeAttributes.nodeName}
  ]

  # Merge disks with the same node
  disks_merged = {
    for disk in data.kubernetes_resources.openebs_blockstorage.objects:
    disk.spec.nodeAttributes.nodeName => [
      for item in local.disks:
      item.disk if item.node == disk.spec.nodeAttributes.nodeName
    ]...
  }
}

Debug Output

Panic Output

│ Error: Plugin did not respond
│
│   with kubernetes_manifest.openebs_cstor_disk_pool_mirrored,
│   on cstor.tf line 1, in resource "kubernetes_manifest" "openebs_cstor_disk_pool_mirrored":
│    1: resource "kubernetes_manifest" "openebs_cstor_disk_pool_mirrored" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).PlanResourceChange call.
│ The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-kubernetes_v2.18.1_x5 plugin:

panic: AttributeName("pools"): can't use tftypes.DynamicPseudoType as tftypes.List[tftypes.Object["dataRaidGroups":tftypes.List[tftypes.Object["blockDevices":tftypes.List[tftypes.Object["blockDeviceName":tftypes.String, "capacity":tftypes.Number, "devLink":tftypes.String]]]], "nodeSelector":tftypes.Map[tftypes.String], "poolConfig":tftypes.Object["auxResources":tftypes.Object["limits":tftypes.Map[tftypes.String], "requests":tftypes.Map[tftypes.String]], "compression":tftypes.String, "dataRaidGroupType":tftypes.String, "priorityClassName":tftypes.String, "resources":tftypes.Object["limits":tftypes.Map[tftypes.String], "requests":tftypes.Map[tftypes.String]], "roThresholdLimit":tftypes.Number, "thickProvision":tftypes.Bool, "tolerations":tftypes.List[tftypes.Object["effect":tftypes.String, "key":tftypes.String, "operator":tftypes.String, "tolerationSeconds":tftypes.Number, "value":tftypes.String]], "writeCacheGroupType":tftypes.String], "writeCacheRaidGroups":tftypes.List[tftypes.Object["blockDevices":tftypes.List[tftypes.Object["blockDeviceName":tftypes.String, "capacity":tftypes.Number, "devLink":tftypes.String]]]]]]

goroutine 143 [running]:
github.com/hashicorp/terraform-plugin-go/tftypes.NewValue(...)
        github.com/hashicorp/terraform-plugin-go@v0.14.2/tftypes/value.go:273
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x22e2c38, 0xc001ea2210?}, {{0x22e2c38?, 0xc001f8e9c0?}, {0x1ce6840?, 0xc001f8e600?}}, 0xc002fa7db8)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:38 +0x2179
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x22e2c38, 0xc001f7bb00?}, {{0x22e2c38?, 0xc001f8eed0?}, {0x1ce6840?, 0xc001f7bd70?}}, 0xc002fa79f8)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:29 +0x1ebe
github.com/hashicorp/terraform-provider-kubernetes/manifest/provider.(*RawProviderServer).PlanResourceChange(0xc0010c4c00, {0x22dc7c0, 0xc001e6c180}, 0xc0002a9590)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/provider/plan.go:366 +0x3994
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.PlanResourceChange({0xc000b0a030, 0xc000b0a090, {0xc0011ce700, 0x2, 0x2}, 0xc000b0a060, 0xc000f289c0, 0xc0011961b0, 0xc000b0a0c0}, {0x22dc7c0, ...}, ...)
        github.com/hashicorp/terraform-plugin-mux@v0.7.0/tf5muxserver/mux_server_PlanResourceChange.go:27 +0x142
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0xc0002b8820, {0x22dc7c0?, 0xc001e618f0?}, 0xc000252e00)
        github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/tf5server/server.go:783 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0x1ebd7c0?, 0xc0002b8820}, {0x22dc7c0, 0xc001e618f0}, 0xc000252d90, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.2/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:367 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0009943c0, {0x22e3280, 0xc001286820}, 0xc001e24fc0, 0xc0012847b0, 0x31fbf88, 0x0)
        google.golang.org/grpc@v1.51.0/server.go:1340 +0xd23
google.golang.org/grpc.(*Server).handleStream(0xc0009943c0, {0x22e3280, 0xc001286820}, 0xc001e24fc0, 0x0)
        google.golang.org/grpc@v1.51.0/server.go:1713 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.51.0/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.51.0/server.go:963 +0x28a

Error: The terraform-provider-kubernetes_v2.18.1_x5 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.

Steps to Reproduce

Expected Behavior

What should have happened?

Actual Behavior

What actually happened?

Important Factoids

Was able to create the resource last week with same config.

References

Community Note

BBBmau commented 1 year ago

Hello! I'll be closing this issue since we just recently merged a PR that addresses this issue. #2055