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

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 = "~> 4.1.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 ~> 4.1 and run terraform init -upgrade

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

v4.1.0 released 4 months, 4 weeks ago
New version approx. every 11 weeks

WARNING: When using the module with multiple node pools avoid changing the order of node pools in the node_pools input of the module. The module always takes the first node pool in the list as directly assigned to the AKS cluster resource thus a change of the order may lead to the AKS cluster recreation.

Create Kubernetes cluster with a single default node pool (subnet mask 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 = "~> 4.1"

  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"

  node_pools = [
    {
      name = "default"

      labels = {
        "project/foo" = "true"
      }
    },
  ]
}
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
node_pools List of node groups to create list(object) 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
node_pools[*].labels A map of key/value pairs 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.