Application Gateway ingress controller is added for aks in terraform file.After adding showing the above error.
My module in azure is below
Cluster Resource Group
resource “azurerm_resource_group” “aks” {
name = var.resource_group_name
location = var.location
}
AKS Cluster Network
module “aks_network” {
source = “…/modules/aks_network”
subnet_name = var.subnet_name
vnet_name = var.vnet_name
name = azurerm_resource_group.aks.name
subnet_cidr = var.subnet_cidr
location = var.location
address_space = var.address_space
app_gateway_subnet_name = var.app_gateway_subnet_name
app_gateway_subnet_address_prefix = var.app_gateway_subnet_address_prefix
}
AKS Log Analytics
module “log_analytics” {
source = “…/modules/log_analytics”
name = azurerm_resource_group.aks.name
log_analytics_workspace_location = var.log_analytics_workspace_location
log_analytics_workspace_name = var.log_analytics_workspace_name
log_analytics_workspace_sku = var.log_analytics_workspace_sku
}
AKS Cluster
module “aks_cluster” {
source = “…/modules/aks-cluster”
cluster_name = var.cluster_name
location = var.location
dns_prefix = var.dns_prefix
name = azurerm_resource_group.aks.name
kubernetes_version = var.kubernetes_version
node_count = var.node_count
min_count = var.min_count
max_count = var.max_count
vm_size = var.vm_size
service_cidr = var.service_cidr
network_plugin = var.network_plugin
vnet_subnet_id = module.aks_network.aks_subnet_id
client_id = var.client_id
client_secret = var.client_secret
environment = var.environment
subnet_id = module.aks_network.subnet_app_gateway_id
}
and below are the variable file for the above module
variables.tf
variable “client_id” {
description = “Azure Service Principal id (client id)”
}
variable “client_secret” {
description = “Azure client Service Principal secret (client secret)”
}
variable resource_group_name {
description = “Resource Group name”
}
variable “node_count” {
description = “number of nodes to deploy”
}
variable “dns_prefix” {
description = “DNS Suffix”
}
variable cluster_name {
description = “AKS cluster name”
}
variable location {
description = “azure location to deploy resources”
}
variable log_analytics_workspace_name {
description = “azure name to deploy log analytics workspace”
}
variable log_analytics_workspace_location {
description = “azure location to deploy log analytics workspace”
}
variable log_analytics_workspace_sku {
description = “azure sku to deploy log analytics workspace”
}
variable subnet_name {
description = “subnet id where the nodes will be deployed”
}
variable vnet_name {
description = “vnet id where the nodes will be deployed”
}
variable subnet_cidr {
description = “the subnet cidr range”
}
variable kubernetes_version {
description = “version of the kubernetes cluster”
}
variable “vm_size” {
description = “size/type of VM to use for nodes”
}
variable “service_cidr” {
description = “size/type of VM to use for nodes”
}
variable “network_plugin” {
description = “size/type of VM to use for nodes”
}
variable “address_space” {
description = “The address space that is used the virtual network”
}
variable “min_count” {
description = “Minimum Node Count”
}
variable “max_count” {
description = “Maximum Node Count”
}
variable “environment” {
description = “Environment”
}
variable “app_gateway_subnet_name” {
description = “App Gateway Subnet Name”
}
variable “app_gateway_subnet_address_prefix” {
description = “App Gateway Subnet Address Prefix”
}
aks_network
main.tf is as below
resource “azurerm_virtual_network” “aks_vnet” {
name = var.vnet_name
address_space = [var.address_space]
resource_group_name = var.name
location = var.location
}
resource “azurerm_subnet” “aks_subnet” {
name = var.subnet_name
resource_group_name = var.name
virtual_network_name = azurerm_virtual_network.aks_vnet.name
address_prefix = var.subnet_cidr
}
resource “azurerm_subnet” “subnet_app_gateway” {
resource_group_name = var.name
virtual_network_name = azurerm_virtual_network.aks_vnet.name
name = var.app_gateway_subnet_name
address_prefix = var.app_gateway_subnet_address_prefix
}
variables.tf
variable “subnet_name” {
description = “name to give the subnet”
}
variable “name” {
description = “resource group that the vnet resides in”
}
variable “vnet_name” {
description = “name of the vnet that this subnet will belong to”
}
variable “subnet_cidr” {
description = “the subnet cidr range”
}
variable “location” {
description = “the cluster location”
}
variable “address_space” {
description = “Network address space”
}
variable “app_gateway_subnet_name” {
description = “App Gateway Subnet Name.”
default = “agw-subnet”
}
variable “app_gateway_subnet_address_prefix” {
description = “Containers DNS server IP address.”
default = “10.100.0.0/24”
}
aks-cluster
main.tf
resource “azurerm_kubernetes_cluster” “cluster” {
name = var.cluster_name
location = var.location
resource_group_name = var.name
dns_prefix = var.dns_prefix
kubernetes_version = var.kubernetes_version
default_node_pool {
name = var.default_pool_name
node_count = var.node_count
vm_size = var.vm_size
vnet_subnet_id = var.vnet_subnet_id
type = var.default_pool_type
enable_auto_scaling = true
min_count = var.min_count
max_count = var.max_count
}
addon_profile {
azure_policy {
enabled = true
}
ingress_application_gateway {
enabled = true
subnet_id = resource.azurerm_subnet.subnet_app_gateway.id
}
}
role_based_access_control {
enabled = true
}
network_profile {
network_plugin = var.network_plugin
network_policy = "azure"
service_cidr = var.service_cidr
dns_service_ip = "10.0.0.10"
docker_bridge_cidr = "172.17.0.1/16"
}
service_principal {
client_id = var.client_id
client_secret = var.client_secret
}
tags = {
Environment = var.environment
}
}
variables.tf
variable “dns_prefix” {
description = “DNS prefix”
}
variable “location” {
description = “azure location to deploy resources”
}
variable “cluster_name” {
description = “AKS cluster name”
}
variable “name” {
description = “name of the resource group to deploy AKS cluster in”
}
variable “kubernetes_version” {
description = “version of the kubernetes cluster”
}
variable “agent_pool_name” {
description = “name for the agent pool profile”
default = “agentpool”
}
variable “agent_pool_type” {
description = “type of the agent pool (AvailabilitySet and VirtualMachineScaleSets)”
default = “VirtualMachineScaleSets”
}
variable “node_count” {
description = “number of nodes to deploy”
}
variable “vm_size” {
description = “size/type of VM to use for nodes”
}
variable “vnet_subnet_id” {
description = “vnet id where the nodes will be deployed”
}
variable “network_plugin” {
description = “network plugin for kubenretes network overlay (azure or calico)”
}
variable “service_cidr” {
description = “kubernetes internal service cidr range”
}
variable “client_id” {
description = “Service principle Client Id”
}
variable “client_secret” {
description = “Service principle Client Secret”
}
variable “min_count” {
description = “Minimum Node Count”
}
variable “max_count” {
description = “Maximum Node Count”
}
variable “default_pool_name” {
description = “name for the agent pool profile”
default = “agentpool”
}
variable “default_pool_type” {
description = “type of the agent pool (AvailabilitySet and VirtualMachineScaleSets)”
default = “VirtualMachineScaleSets”
}
variable “environment” {
description = “Environment”
}