Search code examples
nginxterraformkubernetes-ingressazure-aks

How to create nginx ingress in terraform - aks


How can i create a nginx ingress in azure kubernetes using terraform, earlier in this link , i remember seeing some steps as a mandatory installation for all setups, right now it seems to be removed and there is a specific way of installing for aks in this link, should i rewrite all these to adapt to terraform or is there any other smart way of installing nginx ingress for aks through terraform


Solution

  • You could try using Terraform's helm provider.

    provider "helm" {
        kubernetes {
            host     = azurerm_kubernetes_cluster.your_cluster.kube_config.0.host
            client_key             = base64decode(azurerm_kubernetes_cluster.your_cluster.kube_config.0.client_key)
            client_certificate     = base64decode(azurerm_kubernetes_cluster.your_cluster.kube_config.0.client_certificate)
            cluster_ca_certificate = base64decode(azurerm_kubernetes_cluster.your_cluster.kube_config.0.cluster_ca_certificate)
        }  
    }
    
    data "helm_repository" "stable" {
      name = "stable"
      url  = "https://kubernetes-charts.storage.googleapis.com"
    }
    
    resource "helm_release" "nginix_ingress" {
        name      = "nginx_ingress"
        repository = data.helm_repository.stable.metadata.0.name
        chart     = "stable/nginx-ingress"
        namespace = "kube-system"
    }
    

    If your cluster is already created, you will have to import it as well using a data source. helm_release also supports custom values. Here is the link if you need more information.