<p>I'm trying deploy kubernetes ingress with terraform.
As described here <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/ingress#example-using-nginx-ingress-controller" rel="nofollow noreferrer">link</a> and my own variant:</p>
<pre><code>resource &quot;kubernetes_ingress&quot; &quot;node&quot; {
  metadata {
    name = &quot;node&quot;
  }
  spec {
    ingress_class_name = &quot;nginx&quot;
    rule {
      host = &quot;backend.io&quot;
      http {
        path {
          path = &quot;/&quot;
          backend {
            service_name = kubernetes_service.node.metadata.0.name
            service_port = 3000
          }
        }
      }
    }
  }
}
</code></pre>
<p>error:</p>
<pre><code>╷
│ Error: Failed to create Ingress 'default/node' because: the server could not find the requested resource (post ingresses.extensions)
│ 
│   with kubernetes_ingress.node,
│   on node.tf line 86, in resource &quot;kubernetes_ingress&quot; &quot;node&quot;:
│   86: resource &quot;kubernetes_ingress&quot; &quot;node&quot; {
│ 
╵
</code></pre>
<p>it works:</p>
<p>kubectl apply -f file_below.yaml</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: node
spec:
  ingressClassName: nginx
  rules:
  - host: backend.io
    http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
            service:
              name: node
              port:
               number: 3000
</code></pre>
<p>Need some ideas about how to deploy kubernetes ingress with terraform.</p>

<p>The issue here is that the example in YML is using the proper API version, i.e., <code>networking.k8s.io/v1</code>, hence it works as you probably have a version of K8s higher than 1.19. It is available since that version, the <code>extensions/v1beta1</code> that Ingress was a part of was deprecated in favor of <code>networking.k8s.io/v1</code> in 1.22, as you can read <a href="https://kubernetes.io/docs/reference/using-api/deprecation-guide/#ingress-v122" rel="noreferrer">here</a>. As that is the case, your current Terraform code is using the old K8s API version for Ingress. You can see that on the left-hand side of the documentation menu:</p>
<p><a href="https://i.stack.imgur.com/2tbIX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2tbIX.png" alt="extensionsv1beta1" /></a></p>
<p>If you look further down in the documentation, you will see <code>networking/v1</code> and in the <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/ingress_v1" rel="noreferrer">resource section</a> <code>kubernetes_ingress_v1</code>. Changing the code you have in Terraform to use Ingress from the <code>networking.k8s.io/v1</code>, it becomes:</p>
<pre><code>resource &quot;kubernetes_ingress_v1&quot; &quot;node&quot; {
  metadata {
    name = &quot;node&quot;
  }

  spec {
    ingress_class_name = &quot;nginx&quot;
    rule {
      host = &quot;backend.io&quot;
      http {
        path {
          path = &quot;/*&quot;
          path_type = &quot;ImplementationSpecific&quot;
          backend {
            service {
              name = kubernetes_service.node.metadata.0.name
              port {
                number = 3000
              }
            }
          }
        }
      }
    }
  }
}
</code></pre>
<hr />
