Terraform module to create a managed Kubernetes cluster (AKS) in MS Azure and a User Assigned Identity for it (can be used to access Azure resources from Kubernetes).
Supported Kubernetes versions are 1.29 and newer. Microsoft Azure supported Kubernetes releases.

NOTE: This module is meant to be used with an already created Resource Group and Virtual Network.

The module follows Azure naming conventions. Name variable passed to the module is only suffix used in the full resource names (of AKS and Managed Identity) that are defined by Azure standards.

Abbreviations are used for resource names in most cases, based on these Azure recommendations

WARNING: Support for Windows OS type for node pools is experimental, partial incompatibility or API issues should be expected.

Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_azure_k8s_aks" {
  source  = "solutions.corewide.com/azure/tf-azure-k8s-aks/azurerm"
  version = "~> 5.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 5.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "5.0.0"

v5.0.0 released 1 month, 1 week ago
New version approx. every 11 weeks

Basic AKS cluster configuration with required parameters only (default maintenance node pool is managed unconditionally):

NOTE: a network mask of the associated subnet should be less than /22

 hclresource "azurerm_resource_group" "foo" {
  name     = "foo"
  location = "eastus"
}

module "aks" {
  source  = "solutions.corewide.com/azure/tf-azure-k8s-aks/azurerm"
  version = "~> 5.0"

  name_suffix         = "bar"
  resource_group_name = azurerm_resource_group.foo.name
  region              = azurerm_resource_group.foo.location
  dns_prefix          = "baz"
  subnet_id           = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1"
}

Create AKS cluster with customized maintenance and foo node pools, custom K8s version, network outbound type, and enabled workload identity:

NOTE: a network mask of the associated subnet should be less than /22

 hclresource "azurerm_resource_group" "foo" {
  name     = "foo"
  location = "eastus"
}

module "aks" {
  source  = "solutions.corewide.com/azure/tf-azure-k8s-aks/azurerm"
  version = "~> 5.0"

  name_suffix                       = "bar"
  resource_group_name               = azurerm_resource_group.foo.name
  region                            = azurerm_resource_group.foo.location
  dns_prefix                        = "baz"
  subnet_id                         = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1"
  cluster_version                   = "1.31"
  cluster_network_outbound_type     = "userDefinedRouting"
  cluster_workload_identity_enabled = true

  default_node_pool = {
    node_size = "Standard_D2_v2"
    min_size  = 1
    max_size  = 1
  }

  node_pools = [
    {
      name     = "foo"
      min_size = 1
      max_size = 3
    },
  ]

  tags = {
    Layer = "Computing"
  }
}
Variable Description Type Default Required Sensitive
dns_prefix DNS prefix specified when creating the managed Kubernetes cluster string yes no
name_suffix Naming suffix for the AKS cluster and Managed Identity managed by the module string yes no
region Resource Group location where the managed Kubernetes cluster will be created string yes no
resource_group_name The Resource Group name where the managed Kubernetes cluster will exist string yes no
subnet_id The ID of the Subnet where node pools will be placed into string yes no
allowed_mgmt_networks CIDR blocks allowed to access K8s API list(string) no no
cluster_dns_ip IP address within the Kubernetes service address range that will be used by cluster service discovery string no no
cluster_network_outbound_type The outbound routing method which will be used for the managed Kubernetes cluster (loadBalancer or userDefinedRouting). Changing this parameter forces an AKS cluster recreation string loadBalancer no no
cluster_service_cidr The Network Range used by the AKS. Defaults to 10.0.0.0/16. Should not overlap with subnet_id. IP addressing planning string no no
cluster_version Version of Kubernetes used for the cluster string 1.29 no no
cluster_workload_identity_enabled Indicates whether Azure AD Workload Identity should be enabled for the AKS cluster bool false no no
default_node_pool Default node pool parameters object {} no no
default_node_pool.labels A label map to apply to nodes in the maintenance pool map(string) {} no no
default_node_pool.max_size The maximum number of nodes that the maintenance node pool can be scaled up to number 1 no no
default_node_pool.min_size The minimum number of nodes that the maintenance node pool can be scaled down to number 1 no no
default_node_pool.node_size The type of Droplet to be used as workers in the maintenance node pool string Standard_D2_v2 no no
default_node_pool.os_type OS of the Kubernetes maintenance node group string Linux no no
node_pools List of node groups to create list(object) [] no no
node_pools[*].labels A label map to apply to nodes in the pool map(string) {} no no
node_pools[*].max_size The maximum number of nodes that the node pool can be scaled up to number 1 no no
node_pools[*].min_size The minimum number of nodes that the node pool can be scaled down to number 1 no no
node_pools[*].name A name for the node pool (can only contain lowercase alphanumeric characters and the length must be between 1-12 characters) string yes no
node_pools[*].node_size The type of Droplet to be used as workers in the node pool string Standard_D2_v2 no no
node_pools[*].os_type OS of the Kubernetes node group string Linux no no
tags Tags to attach to cluster resources map(string) {} no no
Output Description Type Sensitive
cluster AKS cluster resource resource yes
node_pools Attributes of all node pools computed no
user_assigned_identity Attributes of Azure User Assigned Identity resource resource no
Dependency Version Kind
terraform >= 1.3 CLI
hashicorp/azurerm ~> 4.0 provider

Not sure where to start?
Let's find your perfect match.