Deployment failing on kubernetes with terraform (the server could not find the requested resource)

I am trying to deploy our created docker image using terrafrom on local kubernetes (k3s). Also creating a service using nginx_ingress. While doing terraform apply getting error. Whatever information I have searched on net it looks like versioning issue but my kuberenetes version is up to date. Terrafrom version is also fine. Please help me to resolve this issue.
Error details are as below -

$ terraform apply --auto-approve
kubernetes_deployment.eve-statedb-deploy: Creating...
kubernetes_horizontal_pod_autoscaler.eve-statedb-hpa: Creating...
kubernetes_secret.eve-statedb-config: Creating...
kubernetes_secret.ghcr-cred: Creating...
Error: the server could not find the requested resource (post secrets)
Error: Failed to create deployment: the server could not find the requested resource (post deployments.apps)
Error: the server could not find the requested resource (post secrets)
Error: the server could not find the requested resource (post horizontalpodautoscalers.autoscaling)

Version information : -

$ sudo kubectl version  --short

Client Version: v1.20.0+k3s2
Server Version: v1.20.0+k3s2

$ terraform --version
Terraform v0.13.6
+ provider registry.terraform.io/hashicorp/kubernetes v2.0.1

This seems to me that it may be a problem with the cluster rather than with Terraform - can you share your configuration so I can try to reproduce?

Thanks for the reply. I am new to terraform and this is my “.tf” file like below

resource "kubernetes_deployment" "sample-statedb-deploy" {
  metadata {
    name = "sample-statedb-deploy"
    labels = {
      app = "sample-statedb"
    }
  }

  spec {
    replicas = 1

    selector {
      match_labels = {
        app = "sample-statedb"
      }
    }

    template {
      metadata {
        labels = {
          app = "sample-statedb"
        }
      }

      spec {
        container {
          image             = "statedb-sample-docker:prd-0.0.4"
          name              = "sample-statedb"
          image_pull_policy = "Always"

          port {
            container_port = 5000
          }

          lifecycle {
            pre_stop {
              exec {
                command = [ "/bin/bash",  "-c", "./config.sh remove --token $(curl -sS --request POST --url \"https://api.github.com/orgs/$${ORG_CODE}/actions/sample-statedbs/remove-token\" --header \"authorization: Bearer $${SVC_TOKEN}\"  --header \"content-type: application/json\" | jq -r .token)" ]
              }
            }
          }          

          resources {
            requests = {
              cpu    = "500m"
              memory = "1024Mi"
            }
            limits = {
              cpu    = "1"
              memory = "2048Mi"
            }
          }
          env {
            name = "SVC_TOKEN" 
              value_from {
                secret_key_ref {
                  name = "sample-statedb-config"
                  key  = "svc-token"  
                }
              }
          }
          env {
            name = "ORG_CODE" 
              value_from {
                secret_key_ref {
                  name = "sample-statedb-config"
                  key  = "org-code"
                }
              }
          } 
        }
        image_pull_secrets {
          name = "img-cred"
        } 
      } 
    }
  }
}
resource "kubernetes_horizontal_pod_autoscaler" "sample-statedb-hpa" {
  metadata {
    name = "sample-statedb-hpa"
  }

  spec {
    max_replicas = 4
    min_replicas = 1

    scale_target_ref {
      kind = "Deployment"
      name = "sample-statedb-deploy"
    }
    target_cpu_utilization_percentage = 75
  }
}

resource "kubernetes_service" "sample-statedb" {
  metadata {
    name = "sample-api-service"
  }
  spec {
    selector = {
      App = kubernetes_deployment.sample-statedb-deploy.metadata[0].labels.app
    }
    port {
      port        = 5000
      target_port = 5000
    }

    type = "LoadBalancer"
  }
}

output "lb_ip" {
  value = kubernetes_service.sample-statedb.status[0].load_balancer[0].ingress[0].ip
}