terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

kubernetes_manifest panics when dealing list of mismatched object shapes

Open KenFigueiredo opened this issue 1 year ago • 5 comments

Hi there, In testing using the kubernetes_manifest for a cluster resource supported by: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere, I'm seeing the following failure which seems to be a byproduct of the provider not properly handling of mixed tuples, which is valid for the spec.

Terraform Version, Provider Version and Kubernetes Version

Terraform version: v1.5.2
Kubernetes provider version: v2.21.1
Kubernetes version: v1.24

Affected Resource(s)

  • kubernetes_manifest

Terraform Configuration Files

resource "kubernetes_manifest" "repro_cluster" {
  manifest = {
    apiVersion = "cluster.x-k8s.io/v1beta1"
    kind       = "Cluster"

    metadata = {
      name        = "repro"
      namespace   = var.cluster_namespace
    }

    spec = {
      clusterNetwork = {
        pods          = { cidrBlocks = var.default_pod_cidr_blocks }
        services      = { cidrBlocks = var.default_service_cidr_blocks }
        serviceDomain = "cluster.local"
      }

      topology = {
        class = "tanzukubernetescluster"
        version = "v1.24..."

        controlPlane = {
          replicas     = var.control_plane_replicas
        }

        workers = {
          machineDeployments = [{
            class = "node-pool"
            name = "repro_pool"
            replicas = 1

            variables = {
              overrides = [
                { name = "vmClass", value = "best-effort-large" },
                # Uncommenting this line results in an error:
                # AttributeName("value"): can't use tftypes.String as tftypes.Tuple[tftypes.Object["effect":tftypes.String,│ "key":tftypes.String, "value":tftypes.String]]
                # { name = "nodePoolTaints", value = [{ key = "foo", effect = "Equals", value = "bar" }] },
              ]
            }
          }]
        }

        variables = [
          # Uncommenting either of these lines results in a panic
          # { name = "nodePoolVolumes", value = [] },
          # { name = "nodePoolTaints", value = [] },
          { name = "storageClass", value = var.default_storage_class },
          { name = "vmClass", value = var.control_plane_vm_class } 
        ]
      }
    }
  }
}

Debug Output

Panic Output

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

panic: interface conversion: tftypes.Type is tftypes.primitive, not tftypes.Tuple

goroutine 317 [running]:
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x10640bc28, 0x1400221f6b0?}, {{0x10640bc80?, 0x1400221fbf0?}, {0x106084f00?, 0x14002200b80?}}, 0x140010c19e0)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:65 +0x16ec
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x10640bb78, 0x14002abdb30?}, {{0x10640bb78?, 0x14002be2360?}, {0x1061440a0?, 0x14002be2090?}}, 0x140010c19b0)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:32 +0x18c4
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x10640bc28, 0x14002abdd10?}, {{0x10640bc28?, 0x14002be2d50?}, {0x1060322e0?, 0x140010c0eb8?}}, 0x140010c18c0)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:81 +0x14e8
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x10640bb78, 0x14002b2e2a0?}, {{0x10640bb78?, 0x14002be73b0?}, {0x1061440a0?, 0x14002bdf140?}}, 0x140010c1710)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:32 +0x18c4
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x10640bb78, 0x14002b2e2d0?}, {{0x10640bb78?, 0x14002be7a40?}, {0x1061440a0?, 0x14002bdda10?}}, 0x140010c1548)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:32 +0x18c4
github.com/hashicorp/terraform-provider-kubernetes/manifest/morph.DeepUnknown({0x10640bb78, 0x14002bdcf30?}, {{0x10640bb78?, 0x14002be82a0?}, {0x1061440a0?, 0x14002bdd1a0?}}, 0x140010c11e8)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/morph/scaffold.go:32 +0x18c4
github.com/hashicorp/terraform-provider-kubernetes/manifest/provider.(*RawProviderServer).PlanResourceChange(0x140011e2e00, {0x1064057a0, 0x140021e4240}, 0x14000f391d0)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/provider/plan.go:369 +0x3144
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.PlanResourceChange({0x14001075b30, 0x14001075b90, {0x140012d6880, 0x2, 0x2}, 0x14001075b60, 0x14001064e90, 0x140012aa7e0, 0x14001075bc0}, {0x1064057a0?, ...}, ...)
        github.com/hashicorp/[email protected]/tf5muxserver/mux_server_PlanResourceChange.go:27 +0x108
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0x14000212b40, {0x1064057a0?, 0x140021d77d0?}, 0x140040b7c00)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:783 +0x3b8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0x10630c8e0?, 0x14000212b40}, {0x1064057a0, 0x140021d77d0}, 0x140040b7b90, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:367 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000c983c0, {0x10640c1c0, 0x140002ee1a0}, 0x140021cd200, 0x140012fbd70, 0x1072a1be8, 0x0)
        google.golang.org/[email protected]/server.go:1340 +0xb7c
google.golang.org/grpc.(*Server).handleStream(0x14000c983c0, {0x10640c1c0, 0x140002ee1a0}, 0x140021cd200, 0x0)
        google.golang.org/[email protected]/server.go:1713 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/[email protected]/server.go:965 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:963 +0x290

Error: The terraform-provider-kubernetes_v2.21.1_x5 plugin crashed!

Steps to Reproduce

  1. Setup terraform file, uncomment line ( { name = "nodePoolTaints", value = [{ key = "foo", effect = "Equals", value = "bar" }] })
  2. terraform plan
  3. Errors out with AttributeName("value"): can't use tftypes.String as tftypes.Tuple[tftypes.Object["effect":tftypes.String,│ "key":tftypes.String, "value":tftypes.String]]
  4. Comment previous line and uncomment line ({ name = "nodePoolVolumes", value = [] },)
  5. terraform plan
  6. panic

Expected Behavior

What should have happened?

No panic, terraform plan runs correctly for the valid CRD spec.

Actual Behavior

What actually happened?

Error / Plugin Panic

Important Factoids

  • N/A

References

  • potentially: https://github.com/hashicorp/terraform/issues/22405

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

KenFigueiredo avatar Jun 29 '23 20:06 KenFigueiredo