# Terraform Errors and How to Debug Them

**URL:** <https://discuss.hashicorp.com/t/terraform-errors-and-how-to-debug-them/44544>\
**Category:** Kubernetes\
**Tags:** helm\
**Created:** [September 20, 2022, 7:58pm UTC](https://discuss.hashicorp.com/t/terraform-errors-and-how-to-debug-them/44544 "2022-09-20T19:58:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hashicorp17](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/hashicorp17/32/24242_2.png) [@hashicorp17](https://discuss.hashicorp.com/u/hashicorp17)\
**Post date:** [September 20, 2022, 7:58pm UTC](https://discuss.hashicorp.com/t/terraform-errors-and-how-to-debug-them/44544/1 "2022-09-20T19:58:19Z")

</div>

Hi everyone,

not sure what I should call the topic of this message. The error message is specific but I wonder how you guys are coping with such errors and how to analyze them. So if you haven’t seen **this** \* very specific error, but can share some details on how to cope with such errors in general, this would be very appreciated!

Some background info: I think the errors origins from a helm provider upgrade and applying some changes, then reverting back the helm provider and now a `terraform plan` spits outs:

```auto
╷
│ Error: Failed to transform List value into Tuple of different length
│
│ with module.dev-k8s.kubernetes_manifest.cert_manager_issuer,
│ on modules/kubernetes/certmanager.tf line 55, in resource "kubernetes_manifest" "cert_manager_issuer":
│ 55: resource "kubernetes_manifest" "cert_manager_issuer" {
│
│ Error: %!s(<nil>)
│ ...at attribute:
│ spec.acme.solvers

```

Line 55 is the first line below:

```auto
resource "kubernetes_manifest" "cert_manager_issuer" {
  manifest = {
    apiVersion = "cert-manager.io/v1"
    kind = "Issuer"
    metadata = {
      name = "letsencrypt-prod"
      namespace = kubernetes_namespace.cert_manager.metadata[0].name
    }
    spec = {
      acme = {
        email = "foo@bar.com"
        server = "https://acme-v02.api.letsencrypt.org/directory"
        privateKeySecretRef = {
          name = "some-key"
        }
        solvers = [
          {
            dns01 = {
              cloudDNS = {
                ...
              }
            }...
          }
        ]
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [September 21, 2022, 7:12pm UTC](https://discuss.hashicorp.com/t/terraform-errors-and-how-to-debug-them/44544/2 "2022-09-21T19:12:14Z")

</div>

Hi @hashicorp17!

Unfortunately I don’t think there’s a _general_ answer to how to diagnose the cause for all errors. Many of Terraform’s error messages include specific suggestions about what might be wrong and/or how to proceed, but there are many different error situations throughout both Terraform Core and all of the providers and so it’s inevitable that some of them will be less complete than others, particularly if describing an unusual situation that the developers didn’t consider.

This error seems to be coming from the `hashicorp/kubernetes` provider itself. I determined that because it says `with module.dev-k8s.kubernetes_manifest.cert_manager_issuer`, which means that Terraform was working on an action against this specific resource instance when the error occurred. (I also happen to know this isn’t a Terraform Core error because I work on Terraform Core, but I understand _that_ heuristic isn’t useful to anyone else but me.)

Because this is a Kubernetes provider error I’ve moved this into the category for the Kubernetes provider since I expect you’re more likely to find someone who is familiar with this class of error in that category.

You did ask for pointers on how to debug _in general_ though, and you’re less likely to hear about that in the new category so in addition to what I shared above I’ll add some other notes about what I might do next:

- When I encounter a provider error I’m unfamiliar with, I typically start by trying to find it in the provider’s own codebase. In this case, that’s [`hashicorp/terraform-provider-kubernetes`](https://github.com/hashicorp/terraform-provider-kubernetes), which you could find via [the provider’s page in Terraform Registry](https://registry.terraform.io/providers/hashicorp/kubernetes).

- In this case I took a guess that “Failed to transform” is probably a fixed, hard-coded string in the codebase even if the subsequent words might be inserted dynamically, and so [I searched for those three words in the repository source code](https://github.com/hashicorp/terraform-provider-kubernetes/search?q=Failed+to+transform).

- At the time I’m writing this, there’s an exact match for that error message in a file called `manifest/morph/morph.go`:

- This code is doing something I’m not super familiar with, but from context (I know what `kubernetes_manifest` is intended to achieve) I’m inferring that what it’s trying to do is convert your overall `manifest` value to match the schema required by this Kubernetes resource type, so that it can submit the manifest to the Kubernetes API.

- I can see in the code which emits the error message that the “at attribute:” part of the message is showing the path within the `manifest` structure that the problem relates to. It refers to `spec.acme.solvers`, which in your example seems to be a tuple of objects.

- This is where the trail runs dry for me based on what I know already: I can see that the expression you wrote is a tuple already, but the error message says it’s converting a list into a tuple. Therefore there seems to be some other prior step which already converted your tuple into a list, and now this is trying to convert it back to a tuple again.

I’m afraid I can’t walk all the way to a solution here because I’ve reached the end of my expertise: I don’t know what is the schema for this resource type’s `spec.acme.solvers` and so I can’t explain what is wrong with the value you assigned to that attribute. However, hopefully you _do_ know what is expected for that particular attribute and can focus on understanding why your value doesn’t match the schema.

---

<div class="post-metadata">

**Author:** ![hashicorp17](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/hashicorp17/32/24242_2.png) [@hashicorp17](https://discuss.hashicorp.com/u/hashicorp17)\
**Post date:** [September 28, 2022, 6:39am UTC](https://discuss.hashicorp.com/t/terraform-errors-and-how-to-debug-them/44544/3 "2022-09-28T06:39:19Z")

</div>

Hi @apparentlymart

thanks a lot for sharing how you analyze such errors! We still haven’t figured out the cause of the error, but the way you walked me through the different steps and thoughts is _excellent_ and really useful!! Thanks a lot for taking the time to write this down.

---

<div class="post-metadata">

**Author:** ![jcogilvie](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jcogilvie/32/37844_2.png) [@jcogilvie](https://discuss.hashicorp.com/u/jcogilvie)\
**Post date:** [September 8, 2023, 5:34pm UTC](https://discuss.hashicorp.com/t/terraform-errors-and-how-to-debug-them/44544/4 "2023-09-08T17:34:00Z")

</div>

@hashicorp17 @apparentlymart this seems to be related to the [relevant CRD](https://github.com/cert-manager/cert-manager/blob/master/deploy/crds/crd-issuers.yaml#L413) setting

```auto
x-kubernetes-preserve-unknown-fields: true

```

which causes [other issues](https://github.com/hashicorp/terraform-provider-kubernetes/issues/2123) with the `kubernetes_manifest` resource because the provider can’t correctly assign a type to something that is basically untyped.
