sl1pm4t / k2tf

Kubernetes YAML to Terraform HCL converter
Mozilla Public License 2.0
1.17k stars 108 forks source link

Support ingress_v1 #98

Closed orgads closed 2 years ago

orgads commented 2 years ago

kubernetes_ingress belongs to v1beta1, while the official v1 release has the more complete kubernetes_ingress_v1. See for example https://github.com/hashicorp/terraform-provider-kubernetes/issues/1023#issuecomment-996533127

Example:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/backend-protocol: https
spec:
  rules:
    - host: my.host.com
      http:
        paths:
          - path: /api/v1/actions/foo
            pathType: Prefix
            backend:
              service:
                name: foo
                port:
                  number: 443

This generates the following errors:

Warn | excluding attribute [kubernetes_ingress.spec.rule.http.path.backend.service.port] not found in Terraform schema  field=Ingress.Spec.Rules.HTTP.Paths.Backend.Service.Port name=foo_ingress type=kubernetes_ingress
Warn | excluding attribute [kubernetes_ingress.spec.rule.http.path.backend.service] not found in Terraform schema  field=Ingress.Spec.Rules.HTTP.Paths.Backend.Service name=foo_ingress type=kubernetes_ingress

And the tf file for spec has only this:

  spec {
    rule {
      host = "my.host.com"

      http {
        path {
          path = "/api/v1/actions/foo"
        }
      }
    }
  }

It misses pathType and the entire backend section.

The following works for me with v1:

resource "kubernetes_ingress_v1" "foo_ingress" {
  metadata {
    name = "foo-ingress"

    annotations = {
      "kubernetes.io/ingress.class"                  = "nginx"
      "nginx.ingress.kubernetes.io/backend-protocol" = "https"
      "nginx.ingress.kubernetes.io/enable-cors"      = "true"
    }
  }

  spec {
    rule {
      host = "my.host.com"

      http {
        path {
          path      = "/api/v1/actions/foo"
          path_type = "Prefix"
          backend {
            service {
              name = "foo"
              port {
                number = 443
              }
            }
          }
        }
      }
    }
  }
}
sl1pm4t commented 2 years ago

Looks like I need to update the Terraform Kubernetes provider dependency so it picks up the networking/v1 changes they added in v2.7.0

jyousefpour commented 2 years ago

Is there any update on this on this release?

munir94 commented 2 years ago

would love to know also . sp i can update my docker image