Azure Kubernetes Service (AKS) Terraform module — parameterised, azurerm 4.x, CI-validated.
This Terraform module creates an Azure Kubernetes Service (AKS) cluster with enterprise-grade security, networking, monitoring, compliance, and DevOps automation features. Designed for production workloads with comprehensive CI/CD, security scanning, and automated compliance validation.
- Kubernetes Cluster: Managed AKS cluster with configurable version and SKU tier
- Private Clusters: Optional private cluster deployment with authorized IP ranges
- Managed Identity: System-assigned or user-assigned managed identity support
- Node Pools: Configurable default and additional node pools with auto-scaling
- Multi-region: Geo-redundant deployments with Azure Front Door integration
- Azure AD Integration: RBAC integration with Azure AD and Azure RBAC
- Workload Identity: Enable workload identity for secure pod-to-resource access
- OIDC Issuer: OpenID Connect issuer for enhanced security
- Key Vault Integration: Secrets provider for Key Vault integration
- Network Policies: Azure network policies for pod-to-pod communication
- Private Endpoints: Private cluster access with private endpoints
- CIS Benchmarks: Automated CIS Kubernetes benchmark validation
- Security Scanning: Integrated Checkov, tfsec, and Trivy scanning
- Azure CNI: Advanced networking with Azure Container Networking Interface
- Load Balancer: Standard or basic load balancer configuration
- API Server Access: Configurable authorized IP ranges for API server
- HTTP Proxy: HTTP proxy configuration for outbound traffic
- Ingress Gateway: Application Gateway ingress controller integration
- Service Mesh: Istio service mesh integration (preview)
- VPN Gateway: Site-to-site VPN connectivity
- Azure Monitor: Container insights and monitoring integration
- Log Analytics: Centralized logging with Log Analytics workspace
- Diagnostic Settings: Comprehensive diagnostic logging and metrics
- Maintenance Windows: Scheduled maintenance windows for cluster updates
- Cost Monitoring: Infracost integration for cost estimation
- Performance Metrics: Real-time performance monitoring and alerting
- CI/CD Pipeline: GitHub Actions with matrix builds and automated testing
- Automated Versioning: Semantic versioning with automated releases
- Dependency Updates: Automated provider and action updates
- Security Scanning: Continuous security vulnerability scanning
- Compliance Checks: Automated policy validation with OPA Conftest
- Infrastructure Testing: Terratest integration for infrastructure validation
- Azure Policy: Policy assignments and initiatives for compliance
- Resource Locks: Prevent accidental deletion of critical resources
- Auto-upgrade: Automatic cluster and node pool upgrades
- Backup & Recovery: Automated backup strategies
- Audit Logging: Comprehensive audit trails and compliance reporting
Pin the module to a release tag:
module "aks" {
source = "git::https://github.com/AIRCLOUD-PL/azure-aks-module.git?ref=v1.0.0"
# required inputs
environment = "..."
location = "..."
location_short = "..."
resource_group_name = "..."
vnet_id = "..."
vnet_subnet_id = "..."
}All inputs and outputs are listed in the generated reference below (Inputs, Outputs). Worked examples live in examples/.
module "aks" {
source = "git::https://github.com/AIRCLOUD-PL/azure-aks-module.git?ref=v1.0.0"
# Required
resource_group_name = "rg-aks-prod"
location = "East US 2"
location_short = "eus2"
environment = "prod"
project_name = "ecommerce"
# Optional - Networking
enable_private_cluster = true
vnet_subnet_id = "/subscriptions/.../subnets/aks"
# Optional - Security
enable_aad_rbac = true
enable_workload_identity = true
enable_key_vault_secrets_provider = true
# Optional - Monitoring
enable_azure_monitor = true
log_analytics_workspace_id = "/subscriptions/.../workspaces/law"
# Optional - Node Pools
default_node_pool_vm_size = "Standard_D4s_v5"
default_node_pool_node_count = 3
enable_auto_scaling = true
tags = {
Environment = "prod"
Project = "ecommerce"
Owner = "platform-team"
}
}module "aks_advanced" {
source = "git::https://github.com/AIRCLOUD-PL/azure-aks-module.git?ref=v1.0.0"
resource_group_name = "rg-aks-advanced"
location = "West Europe"
location_short = "weu"
environment = "prod"
project_name = "data-platform"
# Private cluster with authorized IPs
enable_private_cluster = true
api_server_authorized_ip_ranges = ["10.0.0.0/8", "172.16.0.0/12"]
# Azure AD and RBAC
enable_aad_rbac = true
aad_admin_group_object_ids = ["00000000-0000-0000-0000-000000000000"]
# Workload identity and Key Vault
enable_workload_identity = true
enable_key_vault_secrets_provider = true
# Network configuration
enable_azure_cni = true
network_policy = "azure"
# Monitoring and logging
enable_azure_monitor = true
enable_diagnostic_settings = true
# Default node pool
default_node_pool_vm_size = "Standard_D8s_v5"
default_node_pool_node_count = 3
enable_auto_scaling = true
default_node_pool_min_count = 3
default_node_pool_max_count = 10
# Additional node pools
additional_node_pools = {
"system" = {
name = "system"
vm_size = "Standard_D4s_v5"
node_count = 2
enable_auto_scaling = true
min_count = 2
max_count = 5
node_labels = {
"node-type" = "system"
}
node_taints = [
"CriticalAddonsOnly=true:NoSchedule"
]
}
"user" = {
name = "user"
vm_size = "Standard_D16s_v5"
node_count = 1
enable_auto_scaling = true
min_count = 1
max_count = 20
node_labels = {
"node-type" = "user"
"workload" = "batch"
}
}
}
# Maintenance windows
enable_maintenance_window = true
maintenance_window_allowed = [
{
day = "Sunday"
hours = [2, 3, 4, 5]
}
]
# Resource lock
enable_resource_lock = true
resource_lock_level = "CanNotDelete"
tags = {
Environment = "prod"
Project = "data-platform"
Owner = "data-team"
CostCenter = "data-eng"
Compliance = "pci-dss"
Backup = "daily"
}
}This module includes comprehensive testing:
- Unit Tests: Terraform validation and linting
- Integration Tests: Terratest for infrastructure validation
- Security Tests: Checkov, tfsec, and Trivy scanning
- Compliance Tests: OPA Conftest policy validation
# Run tests
cd test
go test -v ./...
# Validate Terraform
terraform validate
# Format check
terraform fmt -check
# Security scan
checkov -f . --framework terraformThis module implements multiple security layers:
- Network Security: Private clusters, network policies, and firewall rules
- Identity Management: Managed identity and Azure AD integration
- Encryption: At-rest and in-transit encryption
- Access Control: RBAC and least privilege principles
- Security Scanning: Automated vulnerability scanning in CI/CD
- Policy as Code: OPA policies for compliance validation
- Secrets Management: Secure handling of sensitive data
- Audit Logging: Comprehensive audit trails
See SECURITY.md for detailed security information.
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/AIRCLOUD-PL/azure-aks-module.git
cd azure-aks-module
# Install dependencies
terraform init
# Run tests
make test
# Format code
terraform fmt -recursiveThis module is licensed under the MIT License. See LICENSE for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: See SECURITY.md for security-related issues
- Azure Kubernetes Service team
- Terraform and AzureRM provider maintainers
- Open source security scanning tools community
module "aks" {
source = "git::https://github.com/AIRCLOUD-PL/azure-aks-module.git?ref=v1.0.0"
resource_group_name = "rg-aks-basic"
location = "East US"
location_short = "eus"
environment = "dev"
custom_name = "aks-basic"
# VNet configuration
vnet_id = azurerm_virtual_network.example.id
vnet_subnet_id = azurerm_subnet.aks.id
# Cluster configuration
kubernetes_version = "1.27.3"
sku_tier = "Free"
# Identity
enable_managed_identity = true
# Default node pool
default_node_pool_vm_size = "Standard_DS2_v2"
default_node_pool_node_count = 2
enable_auto_scaling = false
default_node_pool_os_disk_size_gb = 128
# Network
enable_azure_cni = true
enable_network_policy = false
dns_service_ip = "10.0.0.10"
service_cidr = "10.0.0.0/16"
load_balancer_sku = "standard"
# Security features
enable_oidc_issuer = true
enable_workload_identity = true
# Monitoring
enable_azure_monitor = false
enable_log_analytics = false
}module "aks_enterprise" {
source = "git::https://github.com/AIRCLOUD-PL/azure-aks-module.git?ref=v1.0.0"
resource_group_name = "rg-aks-enterprise"
location = "East US"
location_short = "eus"
environment = "prod"
custom_name = "aks-enterprise"
# VNet configuration
vnet_id = azurerm_virtual_network.example.id
vnet_subnet_id = azurerm_subnet.aks.id
# Cluster configuration
kubernetes_version = "1.27.3"
sku_tier = "Standard"
# Private cluster
enable_private_cluster = true
enable_api_server_authorized_ip_ranges = true
api_server_authorized_ip_ranges = [
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16"
]
# Identity
enable_managed_identity = true
# Default node pool with auto-scaling
default_node_pool_vm_size = "Standard_DS3_v2"
default_node_pool_node_count = 3
enable_auto_scaling = true
default_node_pool_min_count = 1
default_node_pool_max_count = 10
default_node_pool_os_disk_size_gb = 128
# Additional node pools
additional_node_pools = {
"user-pool" = {
name = "user-pool"
vm_size = "Standard_DS4_v2"
node_count = 2
enable_auto_scaling = true
min_count = 1
max_count = 5
os_disk_size_gb = 128
node_labels = {
"workload" = "user-apps"
}
tags = {
"Purpose" = "User Applications"
}
}
}
# Network
enable_azure_cni = true
enable_network_policy = true
network_policy = "azure"
dns_service_ip = "10.0.0.10"
service_cidr = "10.0.0.0/16"
load_balancer_sku = "standard"
# Azure AD integration
enable_aad_rbac = true
enable_azure_rbac = true
aad_admin_group_object_ids = [
"00000000-0000-0000-0000-000000000000"
]
# Security features
enable_oidc_issuer = true
enable_workload_identity = true
enable_key_vault_secrets_provider = true
key_vault_secrets_provider = {
secret_rotation_enabled = true
secret_rotation_interval = "2m"
}
# Monitoring
enable_azure_monitor = true
enable_log_analytics = true
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
enable_diagnostic_settings = true
# Auto-upgrade
enable_auto_upgrade = true
auto_upgrade_profile = {
upgrade_channel = "stable"
}
# Azure Policy
enable_policy_assignments = true
enable_custom_policies = true
enable_policy_initiative = true
# Resource lock
enable_resource_lock = true
lock_level = "CanNotDelete"
}The module includes comprehensive Terratest suites for validation:
# Run all tests
cd test
go test -v
# Run specific test
go test -v -run TestAKSEnterprise
# Run with verbose output
go test -v -timeout 30m- Private Clusters: Use private clusters for production workloads to restrict API server access
- Network Policies: Enable network policies to control pod-to-pod communication
- Azure AD RBAC: Use Azure AD integration for identity management
- Workload Identity: Enable workload identity for secure access to Azure resources
- Azure Policy: Apply security policies for compliance
- Resource Locks: Use resource locks to prevent accidental deletion
- SKU Tier: Use Free tier for development, Standard for production
- Auto-scaling: Enable auto-scaling to optimize node usage
- Spot Instances: Consider spot instances for non-critical workloads
- Maintenance Windows: Schedule maintenance during off-peak hours
- Network Configuration: Ensure subnet has sufficient IP addresses for nodes and pods
- Identity Permissions: Verify managed identity has required permissions
- Azure Policy: Check policy compliance before deployment
- Resource Quotas: Verify Azure subscription has sufficient quotas
- Enable diagnostic settings for comprehensive logging
- Use Azure Monitor for container insights
- Check Kubernetes logs using kubectl
- Review Azure activity logs for deployment issues
- Follow the existing code style and patterns
- Add comprehensive tests for new features
- Update documentation for any changes
- Ensure backward compatibility
This module is licensed under the MIT License.
| Name | Version |
|---|---|
| terraform | >= 1.5.0 |
| azurerm | ~> 4.0 |
| Name | Version |
|---|---|
| azurerm | 4.81.0 |
No modules.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| aad_admin_group_object_ids | List of Azure AD group object IDs for cluster admins | list(string) |
[] |
no |
| additional_node_pools | Map of additional node pools to create | map(object({ |
{} |
no |
| additional_tags | Additional tags to add to resources | map(string) |
{} |
no |
| api_server_authorized_ip_ranges | List of authorized IP ranges for API server | list(string) |
[] |
no |
| api_server_subnet_id | Subnet ID for API server VNet integration | string |
null |
no |
| created_by | Identifier of who created this resource | string |
"terraform" |
no |
| custom_name | Custom name for the AKS cluster. If provided, name_prefix and name_suffix are ignored | string |
"" |
no |
| default_node_pool_labels | Labels for the default node pool | map(string) |
{} |
no |
| default_node_pool_max_count | Maximum number of nodes in the default node pool | number |
10 |
no |
| default_node_pool_max_pods | Maximum number of pods per node in the default node pool | number |
110 |
no |
| default_node_pool_min_count | Minimum number of nodes in the default node pool | number |
1 |
no |
| default_node_pool_name | Name of the default node pool | string |
"default" |
no |
| default_node_pool_node_count | Number of nodes in the default node pool | number |
3 |
no |
| default_node_pool_os_disk_size_gb | OS disk size in GB for the default node pool | number |
128 |
no |
| default_node_pool_os_disk_type | OS disk type for the default node pool | string |
"Managed" |
no |
| default_node_pool_taints | Taints for the default node pool | list(string) |
[] |
no |
| default_node_pool_vm_size | VM size for the default node pool | string |
"Standard_DS2_v2" |
no |
| diagnostic_logs | List of diagnostic logs to enable | list(string) |
[ |
no |
| diagnostic_metrics | List of diagnostic metrics to enable | list(string) |
[ |
no |
| dns_prefix | DNS prefix for the AKS cluster | string |
"" |
no |
| dns_service_ip | IP address for the DNS service | string |
"10.0.0.10" |
no |
| enable_aad_rbac | Enable Azure AD RBAC for the cluster | bool |
true |
no |
| enable_api_server_authorized_ip_ranges | Enable authorized IP ranges for API server | bool |
true |
no |
| enable_auto_scaling | Enable auto-scaling for the default node pool | bool |
true |
no |
| enable_auto_upgrade | Enable automatic cluster upgrades | bool |
true |
no |
| enable_azure_cni | Enable Azure CNI networking | bool |
true |
no |
| enable_azure_monitor | Enable Azure Monitor for containers | bool |
true |
no |
| enable_azure_rbac | Enable Azure RBAC for Kubernetes authorization | bool |
true |
no |
| enable_custom_policies | Enable custom Azure Policy definitions | bool |
false |
no |
| enable_diagnostic_settings | Enable diagnostic settings | bool |
true |
no |
| enable_http_proxy | Enable HTTP proxy configuration | bool |
false |
no |
| enable_ingress_application_gateway | Enable Application Gateway ingress controller | bool |
false |
no |
| enable_key_vault_secrets_provider | Enable Key Vault secrets provider | bool |
true |
no |
| enable_load_balancer_profile | Enable load balancer profile | bool |
false |
no |
| enable_log_analytics | Enable Log Analytics workspace creation | bool |
true |
no |
| enable_maintenance_window | Enable maintenance window | bool |
false |
no |
| enable_managed_identity | Enable system-assigned managed identity | bool |
true |
no |
| enable_network_policy | Enable network policy | bool |
true |
no |
| enable_oidc_issuer | Enable OIDC issuer | bool |
true |
no |
| enable_policy_assignments | Enable Azure Policy assignments | bool |
true |
no |
| enable_policy_initiative | Enable Azure Policy initiative for AKS security | bool |
true |
no |
| enable_private_cluster | Enable private cluster | bool |
true |
no |
| enable_resource_lock | Enable resource lock for the AKS cluster | bool |
true |
no |
| enable_service_mesh | Enable service mesh | bool |
false |
no |
| enable_workload_identity | Enable workload identity | bool |
true |
no |
| environment | Environment name (dev, test, prod, etc.) | string |
n/a | yes |
| http_proxy_trusted_ca | Trusted CA for HTTP proxy | string |
"" |
no |
| http_proxy_url | HTTP proxy URL | string |
"" |
no |
| https_proxy_url | HTTPS proxy URL | string |
"" |
no |
| ingress_application_gateway_id | Existing Application Gateway ID | string |
null |
no |
| ingress_application_gateway_name | Name for new Application Gateway | string |
null |
no |
| ingress_application_gateway_subnet_cidr | Subnet CIDR for Application Gateway | string |
null |
no |
| ingress_application_gateway_subnet_id | Existing subnet ID for Application Gateway | string |
null |
no |
| key_vault_secret_rotation_enabled | Enable secret rotation for Key Vault provider | bool |
true |
no |
| key_vault_secret_rotation_interval | Secret rotation interval | string |
"2m" |
no |
| kubernetes_version | Kubernetes version for the AKS cluster | string |
"1.27.3" |
no |
| load_balancer_sku | SKU for the load balancer | string |
"standard" |
no |
| location | Azure region for the AKS cluster | string |
n/a | yes |
| location_short | Short name for the location (e.g., 'eus' for East US) | string |
n/a | yes |
| log_analytics_retention_days | Retention period for Log Analytics data | number |
30 |
no |
| log_analytics_sku | SKU for Log Analytics workspace | string |
"PerGB2018" |
no |
| log_analytics_workspace_id | Existing Log Analytics workspace ID | string |
null |
no |
| maintenance_window_allowed | List of allowed maintenance windows | list(object({ |
[] |
no |
| maintenance_window_not_allowed | List of not allowed maintenance windows | list(object({ |
[] |
no |
| managed_outbound_ip_count | Number of managed outbound IPs | number |
1 |
no |
| name_prefix | Prefix for resource naming. If empty, defaults to 'aks-{environment}-{location_short}' | string |
"" |
no |
| name_suffix | Suffix for resource naming | string |
"" |
no |
| no_proxy_list | List of addresses to exclude from proxy | list(string) |
[] |
no |
| node_resource_group | Resource group for cluster nodes. If empty, defaults to {resource_group_name}-aks-nodes | string |
"" |
no |
| outbound_ip_address_ids | List of outbound IP address IDs | list(string) |
[] |
no |
| outbound_ip_prefix_ids | List of outbound IP prefix IDs | list(string) |
[] |
no |
| project_name | Name of the project | string |
"enterprise" |
no |
| resource_group_id | Resource group ID for policy assignments | string |
null |
no |
| resource_group_name | Name of the resource group | string |
n/a | yes |
| resource_lock_level | Level of the resource lock | string |
"CanNotDelete" |
no |
| service_cidr | CIDR for the service network | string |
"10.0.0.0/16" |
no |
| service_mesh_mode | Service mesh mode | string |
"Istio" |
no |
| sku_tier | SKU tier for the AKS cluster (Free or Paid) | string |
"Free" |
no |
| upgrade_channel | Upgrade channel for automatic upgrades | string |
"stable" |
no |
| upgrade_max_surge | Maximum surge for upgrades | string |
"10%" |
no |
| vnet_id | Virtual network ID for the AKS cluster | string |
n/a | yes |
| vnet_subnet_id | Subnet ID for the AKS cluster nodes | string |
n/a | yes |
| Name | Description |
|---|---|
| aks_aad_rbac_enabled | Whether Azure AD RBAC is enabled |
| aks_additional_node_pools | Map of additional node pools created |
| aks_api_server_authorized_ip_ranges | The authorized IP ranges for API server access |
| aks_auto_scaling_enabled | Whether auto-scaling is enabled for the default node pool |
| aks_auto_upgrade_enabled | Whether auto-upgrade is enabled |
| aks_azure_monitor_enabled | Whether Azure Monitor is enabled |
| aks_azure_rbac_enabled | Whether Azure RBAC is enabled |
| aks_client_certificate | The client certificate for the AKS cluster |
| aks_client_key | The client key for the AKS cluster |
| aks_cluster_ca_certificate | The cluster CA certificate for the AKS cluster |
| aks_cluster_fqdn | The FQDN of the AKS cluster |
| aks_cluster_id | The ID of the AKS cluster |
| aks_cluster_name | The name of the AKS cluster |
| aks_cluster_portal_fqdn | The portal FQDN of the AKS cluster |
| aks_cluster_private_fqdn | The private FQDN of the AKS cluster |
| aks_default_node_pool | The default node pool configuration |
| aks_diagnostic_setting_id | The ID of the diagnostic setting |
| aks_host | The Kubernetes cluster server host |
| aks_http_proxy_enabled | Whether HTTP proxy is enabled |
| aks_identity | The identity configuration of the AKS cluster |
| aks_ingress_application_gateway_enabled | Whether Application Gateway ingress is enabled |
| aks_key_vault_secrets_provider_enabled | Whether Key Vault secrets provider is enabled |
| aks_kube_config | The kubeconfig for the AKS cluster |
| aks_kube_config_raw | The raw kubeconfig for the AKS cluster |
| aks_kubernetes_version | The Kubernetes version of the AKS cluster |
| aks_location | The location of the AKS cluster |
| aks_log_analytics_workspace_id | The ID of the Log Analytics workspace |
| aks_log_analytics_workspace_name | The name of the Log Analytics workspace |
| aks_maintenance_window_enabled | Whether maintenance window is enabled |
| aks_network_policy_enabled | Whether network policy is enabled |
| aks_network_profile | The network profile of the AKS cluster |
| aks_node_resource_group | The resource group containing the AKS cluster nodes |
| aks_oidc_issuer_url | The OIDC issuer URL of the AKS cluster |
| aks_policy_assignment_id | The ID of the Azure Policy assignment |
| aks_private_cluster_enabled | Whether the AKS cluster is private |
| aks_resource_group_name | The resource group name of the AKS cluster |
| aks_resource_lock_id | The ID of the resource lock |
| aks_service_mesh_enabled | Whether service mesh is enabled |
| aks_sku_tier | The SKU tier of the AKS cluster |
| aks_tags | Tags applied to the AKS cluster |
| aks_upgrade_channel | The upgrade channel for the AKS cluster |
| aks_user_assigned_identity_client_id | The client ID of the user-assigned identity |
| aks_user_assigned_identity_id | The ID of the user-assigned identity |
| aks_user_assigned_identity_principal_id | The principal ID of the user-assigned identity |
| aks_workload_identity_enabled | Whether workload identity is enabled |
Browse all modules with usage snippets in the module catalog or on github.com/AIRCLOUD-PL. Built and maintained by AIRCLOUD: DevOps, cloud and AI engineering. Need a hand with Azure landing zones or platform engineering? See aircloud.com.pl/consulting.
