Terraform - How to enable Azure Application Gateway Ingress Controller when setting up Kubernetes

Following the guide from Microsoft on how to "Create a Kubernetes cluster with Azure Kubernetes Service using Terraform" you can easily set up a Kubernetes cluster on Azure. However, after you have done this you will not have an ingress controller as this is not created together with the cluster.

Below is the full example from the microsoft page on how to create a cluster, with the addition on how to create the AGIC:

resource "azurerm_kubernetes_cluster" "k8s" {
    name                = var.cluster_name
    location            = azurerm_resource_group.k8s.location
    resource_group_name = azurerm_resource_group.k8s.name
    dns_prefix          = var.dns_prefix
	kubernetes_version  = "1.21.2"

    linux_profile {
        admin_username = "ubuntu"

        ssh_key {
            key_data = file(var.ssh_public_key)
        }
    }

    default_node_pool {
        name            = "agentpool"
        node_count      = var.agent_count
        vm_size         = "Standard_DS2_v2"
    }

    service_principal {
        client_id     = var.client_id
        client_secret = var.client_secret
    }

    addon_profile {
        oms_agent {
			enabled                    = true
			log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
        }
			ingress_application_gateway  {
			enabled                    = true 
			subnet_cidr                = "10.1.0.0/16"
			gateway_name               = "${var.cluster_name}-AGIC"
		}
    }

    network_profile {
        load_balancer_sku = "Standard"
        network_plugin = "kubenet"
    }

    tags = {
        Environment = "Development"
    }
}

The interesting part is below. Here the ingress application gateway is created:

ingress_application_gateway  {
	enabled                    = true 
	subnet_cidr                = "10.1.0.0/16"
	gateway_name               = "${var.cluster_name}-AGIC"
}

You can see the full documentation here. I hope you found this helpful, feel free to leave a comment down below!