<p>I'm trying to apply a terraform resource (helm_release) to k8s and the apply command is failed half way through.</p>
<p>I checked the pod issue now I need to update some values in the local chart.</p>
<p>Now I'm in a dilemma, where I can't apply the helm_release as the names are in use, and I can't destroy the helm_release since it is not created.</p>
<p>Seems to me the only option is to manually delete the k8s resources that were created by the helm_release chart?</p>
<p>Here is the terraform for helm_release:</p>
<pre><code>cat nginx-arm64.tf 

resource &quot;helm_release&quot; &quot;nginx-ingress&quot; {
  name  = &quot;nginx-ingress&quot;
  chart = &quot;/data/terraform/k8s/nginx-ingress-controller-arm64.tgz&quot;
}
</code></pre>
<p>BTW: I need to use the local chart as the official chart does not support the ARM64 architecture.
Thanks,</p>
<p>Edit #1:</p>
<p>Here is the list of helm release -&gt; there is no gninx ingress</p>
<pre><code>/data/terraform/k8s$ helm list -A
NAME            NAMESPACE   REVISION    UPDATED                                 STATUS      CHART               APP VERSION
cert-manager    default     1           2021-12-08 20:57:38.979176622 +0000 UTC deployed    cert-manager-v1.5.0 v1.5.0     
/data/terraform/k8s$ 
</code></pre>
<p>Here is the describe pod output:</p>
<pre><code>$ k describe pod/nginx-ingress-nginx-ingress-controller-99cddc76b-62nsr
Name:         nginx-ingress-nginx-ingress-controller-99cddc76b-62nsr
Namespace:    default
Priority:     0
Node:         ocifreevmalways/10.0.0.189
Start Time:   Wed, 08 Dec 2021 11:11:59 +0000
Labels:       app.kubernetes.io/component=controller
              app.kubernetes.io/instance=nginx-ingress
              app.kubernetes.io/managed-by=Helm
              app.kubernetes.io/name=nginx-ingress-controller
              helm.sh/chart=nginx-ingress-controller-9.0.9
              pod-template-hash=99cddc76b
Annotations:  &lt;none&gt;
Status:       Running
IP:           10.244.0.22
IPs:
  IP:           10.244.0.22
Controlled By:  ReplicaSet/nginx-ingress-nginx-ingress-controller-99cddc76b
Containers:
  controller:
    Container ID:  docker://0b75f5f68ef35dfb7dc5b90f9d1c249fad692855159f4e969324fc4e2ee61654
    Image:         docker.io/rancher/nginx-ingress-controller:nginx-1.1.0-rancher1
    Image ID:      docker-pullable://rancher/nginx-ingress-controller@sha256:177fb5dc79adcd16cb6c15d6c42cef31988b116cb148845893b6b954d7d593bc
    Ports:         80/TCP, 443/TCP
    Host Ports:    0/TCP, 0/TCP
    Args:
      /nginx-ingress-controller
      --default-backend-service=default/nginx-ingress-nginx-ingress-controller-default-backend
      --election-id=ingress-controller-leader
      --controller-class=k8s.io/ingress-nginx
      --configmap=default/nginx-ingress-nginx-ingress-controller
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    255
      Started:      Wed, 08 Dec 2021 22:02:15 +0000
      Finished:     Wed, 08 Dec 2021 22:02:15 +0000
    Ready:          False
    Restart Count:  132
    Liveness:       http-get http://:10254/healthz delay=10s timeout=1s period=10s #success=1 #failure=3
    Readiness:      http-get http://:10254/healthz delay=10s timeout=1s period=10s #success=1 #failure=3
    Environment:
      POD_NAME:       nginx-ingress-nginx-ingress-controller-99cddc76b-62nsr (v1:metadata.name)
      POD_NAMESPACE:  default (v1:metadata.namespace)
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-wzqqn (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-wzqqn:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       &lt;nil&gt;
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              &lt;none&gt;
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason   Age                     From     Message
  ----     ------   ----                    ----     -------
  Normal   Pulled   8m38s (x132 over 10h)   kubelet  Container image &quot;docker.io/rancher/nginx-ingress-controller:nginx-1.1.0-rancher1&quot; already present on machine
  Warning  BackOff  3m39s (x3201 over 10h)  kubelet  Back-off restarting failed container

</code></pre>
<p>The terraform state list shows nothing:</p>
<pre><code>/data/terraform/k8s$ t state list
/data/terraform/k8s$ 
</code></pre>
<p>Though the terraform.tfstate.backup shows the nginx ingress (I guess that I did run the destroy command in between?):</p>
<pre><code>/data/terraform/k8s$ cat terraform.tfstate.backup
{
  &quot;version&quot;: 4,
  &quot;terraform_version&quot;: &quot;1.0.11&quot;,
  &quot;serial&quot;: 28,
  &quot;lineage&quot;: &quot;30e74aa5-9631-f82f-61a2-7bdbd97c2276&quot;,
  &quot;outputs&quot;: {},
  &quot;resources&quot;: [
    {
      &quot;mode&quot;: &quot;managed&quot;,
      &quot;type&quot;: &quot;helm_release&quot;,
      &quot;name&quot;: &quot;nginx-ingress&quot;,
      &quot;provider&quot;: &quot;provider[\&quot;registry.terraform.io/hashicorp/helm\&quot;]&quot;,
      &quot;instances&quot;: [
        {
          &quot;status&quot;: &quot;tainted&quot;,
          &quot;schema_version&quot;: 0,
          &quot;attributes&quot;: {
            &quot;atomic&quot;: false,
            &quot;chart&quot;: &quot;/data/terraform/k8s/nginx-ingress-controller-arm64.tgz&quot;,
            &quot;cleanup_on_fail&quot;: false,
            &quot;create_namespace&quot;: false,
            &quot;dependency_update&quot;: false,
            &quot;description&quot;: null,
            &quot;devel&quot;: null,
            &quot;disable_crd_hooks&quot;: false,
            &quot;disable_openapi_validation&quot;: false,
            &quot;disable_webhooks&quot;: false,
            &quot;force_update&quot;: false,
            &quot;id&quot;: &quot;nginx-ingress&quot;,
            &quot;keyring&quot;: null,
            &quot;lint&quot;: false,
            &quot;manifest&quot;: null,
            &quot;max_history&quot;: 0,
            &quot;metadata&quot;: [
              {
                &quot;app_version&quot;: &quot;1.1.0&quot;,
                &quot;chart&quot;: &quot;nginx-ingress-controller&quot;,
                &quot;name&quot;: &quot;nginx-ingress&quot;,
                &quot;namespace&quot;: &quot;default&quot;,
                &quot;revision&quot;: 1,
                &quot;values&quot;: &quot;{}&quot;,
                &quot;version&quot;: &quot;9.0.9&quot;
              }
            ],
            &quot;name&quot;: &quot;nginx-ingress&quot;,
            &quot;namespace&quot;: &quot;default&quot;,
            &quot;postrender&quot;: [],
            &quot;recreate_pods&quot;: false,
            &quot;render_subchart_notes&quot;: true,
            &quot;replace&quot;: false,
            &quot;repository&quot;: null,
            &quot;repository_ca_file&quot;: null,
            &quot;repository_cert_file&quot;: null,
            &quot;repository_key_file&quot;: null,
            &quot;repository_password&quot;: null,
            &quot;repository_username&quot;: null,
            &quot;reset_values&quot;: false,
            &quot;reuse_values&quot;: false,
            &quot;set&quot;: [],
            &quot;set_sensitive&quot;: [],
            &quot;skip_crds&quot;: false,
            &quot;status&quot;: &quot;failed&quot;,
            &quot;timeout&quot;: 300,
            &quot;values&quot;: null,
            &quot;verify&quot;: false,
            &quot;version&quot;: &quot;9.0.9&quot;,
            &quot;wait&quot;: true,
            &quot;wait_for_jobs&quot;: false
          },
          &quot;sensitive_attributes&quot;: [],
          &quot;private&quot;: &quot;bnVsbA==&quot;
        }
      ]
    }
  ]
}
</code></pre>
<p>When I try to apply in the same directory, it prompts the error again:</p>
<pre><code>Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

helm_release.nginx-ingress: Creating...
╷
│ Error: cannot re-use a name that is still in use
│ 
│   with helm_release.nginx-ingress,
│   on nginx-arm64.tf line 1, in resource &quot;helm_release&quot; &quot;nginx-ingress&quot;:
│    1: resource &quot;helm_release&quot; &quot;nginx-ingress&quot; {
</code></pre>
<p>Please share your thoughts. Thanks.</p>
<p>Edit2:</p>
<p>The DEBUG logs show some more clues:</p>
<pre><code>2021-12-09T04:30:14.118Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceDiff: nginx-ingress] Release validated: timestamp=2021-12-09T04:30:14.118Z
2021-12-09T04:30:14.118Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceDiff: nginx-ingress] Done: timestamp=2021-12-09T04:30:14.118Z
2021-12-09T04:30:14.119Z [WARN]  Provider &quot;registry.terraform.io/hashicorp/helm&quot; produced an invalid plan for helm_release.nginx-ingress, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .cleanup_on_fail: planned value cty.False for a non-computed attribute
      - .create_namespace: planned value cty.False for a non-computed attribute
      - .verify: planned value cty.False for a non-computed attribute
      - .recreate_pods: planned value cty.False for a non-computed attribute
      - .render_subchart_notes: planned value cty.True for a non-computed attribute
      - .replace: planned value cty.False for a non-computed attribute
      - .reset_values: planned value cty.False for a non-computed attribute
      - .disable_crd_hooks: planned value cty.False for a non-computed attribute
      - .lint: planned value cty.False for a non-computed attribute
      - .namespace: planned value cty.StringVal(&quot;default&quot;) for a non-computed attribute
      - .skip_crds: planned value cty.False for a non-computed attribute
      - .disable_webhooks: planned value cty.False for a non-computed attribute
      - .force_update: planned value cty.False for a non-computed attribute
      - .timeout: planned value cty.NumberIntVal(300) for a non-computed attribute
      - .reuse_values: planned value cty.False for a non-computed attribute
      - .dependency_update: planned value cty.False for a non-computed attribute
      - .disable_openapi_validation: planned value cty.False for a non-computed attribute
      - .atomic: planned value cty.False for a non-computed attribute
      - .wait: planned value cty.True for a non-computed attribute
      - .max_history: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .wait_for_jobs: planned value cty.False for a non-computed attribute
helm_release.nginx-ingress: Creating...
2021-12-09T04:30:14.119Z [INFO]  Starting apply for helm_release.nginx-ingress
2021-12-09T04:30:14.119Z [INFO]  Starting apply for helm_release.nginx-ingress
2021-12-09T04:30:14.119Z [DEBUG] helm_release.nginx-ingress: applying the planned Create change
2021-12-09T04:30:14.120Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] setting computed for &quot;metadata&quot; from ComputedKeys: timestamp=2021-12-09T04:30:14.120Z
2021-12-09T04:30:14.120Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceReleaseCreate: nginx-ingress] Started: timestamp=2021-12-09T04:30:14.120Z
2021-12-09T04:30:14.120Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceReleaseCreate: nginx-ingress] Getting helm configuration: timestamp=2021-12-09T04:30:14.120Z
2021-12-09T04:30:14.120Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [INFO] GetHelmConfiguration start: timestamp=2021-12-09T04:30:14.120Z
2021-12-09T04:30:14.120Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] Using kubeconfig: /home/ubuntu/.kube/config: timestamp=2021-12-09T04:30:14.120Z
2021-12-09T04:30:14.120Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [INFO] Successfully initialized kubernetes config: timestamp=2021-12-09T04:30:14.120Z
2021-12-09T04:30:14.121Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [INFO] GetHelmConfiguration success: timestamp=2021-12-09T04:30:14.121Z
2021-12-09T04:30:14.121Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceReleaseCreate: nginx-ingress] Getting chart: timestamp=2021-12-09T04:30:14.121Z
2021-12-09T04:30:14.125Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceReleaseCreate: nginx-ingress] Preparing for installation: timestamp=2021-12-09T04:30:14.125Z
2021-12-09T04:30:14.125Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 ---[ values.yaml ]-----------------------------------
{}: timestamp=2021-12-09T04:30:14.125Z
2021-12-09T04:30:14.125Z [INFO]  provider.terraform-provider-helm_v2.4.1_x5: 2021/12/09 04:30:14 [DEBUG] [resourceReleaseCreate: nginx-ingress] Installing chart: timestamp=2021-12-09T04:30:14.125Z
╷
│ Error: cannot re-use a name that is still in use
│ 
│   with helm_release.nginx-ingress,
│   on nginx-arm64.tf line 1, in resource &quot;helm_release&quot; &quot;nginx-ingress&quot;:
│    1: resource &quot;helm_release&quot; &quot;nginx-ingress&quot; {
│ 
╵
2021-12-09T04:30:14.158Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err=&quot;rpc error: code = Unavailable desc = transport is closing&quot;
2021-12-09T04:30:14.160Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/helm/2.4.1/linux_arm64/terraform-provider-helm_v2.4.1_x5 pid=558800
2021-12-09T04:30:14.160Z [DEBUG] provider: plugin exited

</code></pre>

<p>You don't have to manually delete all the resources using <code>kubectl</code>. Under the hood the Terraform Helm provider still uses Helm. So if you run <code>helm list -A</code> you will see all the Helm releases on your cluster, including the <code>nginx-ingress</code> release. Deleting the release is then done via <code>helm uninstall nginx-ingress -n REPLACE_WITH_YOUR_NAMESPACE</code>.</p>
<p>Before re-running <code>terraform apply</code> do check if the Helm release is still in your Terraform state via <code>terraform state list</code> (run this from the same directory as where you run <code>terraform apply</code> from). If you don't see <code>helm_release.nginx-ingress</code> in that list then it is not in your Terraform state and you can just rerun your <code>terraform apply</code>. Else you have to delete it via <code>terraform state rm helm_release.nginx-ingress</code> and then you can run <code>terraform apply</code> again.</p>
