<p>I'm trying to deploy an Application Load Balancer to AWS using Terraform's <code>kubernetes_ingress</code> resource:</p>
<p>I'm using <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.3/" rel="nofollow noreferrer">aws-load-balancer-controller</a> which I've installed using <code>helm_release</code> resource to my cluster.</p>
<p>Now I'm trying to deploy a <code>deployment</code> with a <code>service</code> and <code>ingress</code>.</p>
<p>This is how my <code>service</code> looks like:</p>
<pre><code>resource &quot;kubernetes_service&quot; &quot;questo-server-service&quot; {
  metadata {
    name      = &quot;questo-server-service-${var.env}&quot;
    namespace = kubernetes_namespace.app-namespace.metadata.0.name
  }
  spec {
    selector = {
      &quot;app.kubernetes.io/name&quot; = lookup(kubernetes_deployment.questo-server.metadata.0.labels, &quot;app.kubernetes.io/name&quot;)
    }

    port {
      port        = 80
      target_port = 4000
    }
    type = &quot;LoadBalancer&quot;
  }
}
</code></pre>
<p>And this is how my <code>ingress</code> looks like:</p>
<pre><code>resource &quot;kubernetes_ingress&quot; &quot;questo-server-ingress&quot; {
  wait_for_load_balancer = true
  metadata {
    name = &quot;questo-server-ingress-${var.env}&quot;
    namespace = kubernetes_namespace.app-namespace.metadata.0.name
    annotations = {
      &quot;kubernetes.io/ingress.class&quot; = &quot;alb&quot;
      &quot;alb.ingress.kubernetes.io/target-type&quot; = &quot;instance&quot;
    }
  }
  spec {
    rule {
      http {
        path {
          path = &quot;/*&quot;
          backend {
            service_name = kubernetes_service.questo-server-service.metadata.0.name
            service_port = 80
          }
        }
      }
    }
  }
}
</code></pre>
<p>The issue is that when I run <code>terraform apply</code> it creates a Classic Load Balancer instead of an Application Load Balancer.</p>
<p>I've tried changing <code>service</code>'s type to <code>NodePort</code> but it didn't help.</p>
<p>I've also tried with adding more annotations to <code>ingress</code> like <code>&quot;alb.ingress.kubernetes.io/load-balancer-name&quot; = &quot;${name}&quot;</code> but then the it created two load balancers at once! One internal ALB and one internet facing CLB.</p>
<p>Any ideas how I can create an internet facing Application Load Balancer using this setup?</p>
<p>--- Update ----</p>
<p>I've noticed, that actually, the <code>service</code> is the Classic Load Balancer via which I can connect to my <code>deployment</code>.</p>
<p>Ingress creates an ALB, but it's prefixed with <code>internal</code>, so my questions here is, how to create an internet facing ALB?</p>
<p>Thanks!</p>

matewilk
<p>Answering my own question, like most of the times :)</p>
<p>This is the proper setup, just in case someone come across it:</p>
<p>The <code>service</code>'s type has to be <code>NodePort</code>:</p>
<pre><code>resource &quot;kubernetes_service&quot; &quot;questo-server-service&quot; {
  metadata {
    name      = &quot;questo-server-service-${var.env}&quot;
    namespace = kubernetes_namespace.app-namespace.metadata.0.name
  }
  spec {
    selector = {
      &quot;app.kubernetes.io/name&quot; = lookup(kubernetes_deployment.questo-server.metadata.0.labels, &quot;app.kubernetes.io/name&quot;)
    }

    port {
      port        = 80
      target_port = 4000
    }
    type = &quot;NodePort&quot;
  }
}
</code></pre>
<p>And <code>ingress</code>'s annotation has to be set as follows: (you can ingnore <code>load-balancer-name</code> and <code>healthcheck-pass</code> as they are not relevant to the question:</p>
<pre><code>resource &quot;kubernetes_ingress&quot; &quot;questo-server-ingress&quot; {
  wait_for_load_balancer = true
  metadata {
    name      = &quot;questo-server-ingress-${var.env}&quot;
    namespace = kubernetes_namespace.app-namespace.metadata.0.name
    annotations = {
      &quot;kubernetes.io/ingress.class&quot;                  = &quot;alb&quot;
      &quot;alb.ingress.kubernetes.io/target-type&quot;        = &quot;ip&quot;
      &quot;alb.ingress.kubernetes.io/scheme&quot;             = &quot;internet-facing&quot;
      &quot;alb.ingress.kubernetes.io/load-balancer-name&quot; = &quot;questo-server-alb-${var.env}&quot;
      &quot;alb.ingress.kubernetes.io/healthcheck-path&quot;   = &quot;/health&quot;
    }
  }

  spec {
    rule {
      http {
        path {
          path = &quot;/*&quot;
          backend {
            service_name = kubernetes_service.questo-server-service.metadata.0.name
            service_port = 80
          }
        }
      }
    }
  }
} 
</code></pre>
