<p>I am using terraform to deploy a kube cluster to Google Kubernetes Engine.</p>
<p>Here is my ingress config - both http and https are working but I want http to auto redirect to https</p>
<pre><code>resource &quot;kubernetes_ingress_v1&quot; &quot;ingress&quot; {
  wait_for_load_balancer = true
  metadata {
    name = &quot;ingress&quot;
  }
  spec {
    default_backend {
      service {
        name = kubernetes_service.frontend_service.metadata[0].name
        port {
          number = 80
        }
      }
    }
    rule {
      http {
        path {
          backend {
            service {
              name = kubernetes_service.api_service.metadata[0].name
              port {
                number = 80
              }
            }
          }
          path = &quot;/api/*&quot;
        }

        path {
          backend {
            service {
              name = kubernetes_service.api_service.metadata[0].name
              port {
                number = 80
              }
            }
          }
          path = &quot;/api&quot;
        }
      }
    }
    tls {

      secret_name = &quot;tls-secret&quot;
    }
  }
  depends_on = [kubernetes_secret_v1.tls-secret, kubernetes_service.frontend_service, kubernetes_service.api_service]
}

</code></pre>
<p>How can I configure the ingress to auto redirect from http to https?</p>

<p>The following worked for me - I got my hints from <a href="https://github.com/hashicorp/terraform-provider-kubernetes/issues/1326#issuecomment-910374103" rel="nofollow noreferrer">https://github.com/hashicorp/terraform-provider-kubernetes/issues/1326#issuecomment-910374103</a></p>
<pre><code>

resource &quot;kubectl_manifest&quot; &quot;app-frontend-config&quot; {
  wait_for_rollout = true
  yaml_body = yamlencode({
    apiVersion = &quot;networking.gke.io/v1beta1&quot;
    kind       = &quot;FrontendConfig&quot;
    metadata = {
      name = &quot;ingress-fc&quot;
    }
    spec = {
      redirectToHttps = {
        enabled = true
      }
    }
  })
}



resource &quot;kubernetes_ingress_v1&quot; &quot;ingress&quot; {
  wait_for_load_balancer = true
  metadata {
    name = &quot;ingress&quot;
    annotations = {
      &quot;networking.gke.io/v1beta1.FrontendConfig&quot;         = kubectl_manifest.app-frontend-config.name
    }

  }
  spec {
    default_backend {
      service {
        name = kubernetes_service.frontend_service.metadata[0].name
        port {
          number = 80
        }
      }
    }
    rule {
      http {
        path {
          backend {
            service {
              name = kubernetes_service.api_service.metadata[0].name
              port {
                number = 80
              }
            }
          }
          path = &quot;/api/*&quot;
        }

        path {
          backend {
            service {
              name = kubernetes_service.api_service.metadata[0].name
              port {
                number = 80
              }
            }
          }
          path = &quot;/api&quot;
        }
      }
    }
    tls {

      secret_name = &quot;tls-secret&quot;
    }
  }
  depends_on = [kubernetes_secret_v1.tls-secret, kubernetes_service.frontend_service, kubernetes_service.api_service]
}

</code></pre>
<p>You need an additional module in your <code>terraform</code> block</p>
<pre><code>   
    kubectl = {
      source  = &quot;gavinbunney/kubectl&quot;
      version = &quot;&gt;= 1.14.0&quot;
    }


</code></pre>
<p>Do not forget to initialise the kubectl provider</p>
<pre><code>
provider &quot;kubectl&quot; {
  host                   = &quot;https://${google_container_cluster.primary.endpoint}&quot;
  token                  = data.google_client_config.default.access_token
  cluster_ca_certificate = base64decode(google_container_cluster.primary.master_auth[0].cluster_ca_certificate)
  load_config_file       = false
}

</code></pre>
