Deploy an Azure Kubernetes Service (AKS) Cluster With Terraform

In this blog, I will show you how to create an Azure Kubernetes Service (AKS) cluster with Terraform.


In the last few blog post, we learned how to create an AKS cluster with ARM, and now it is time to create one with Terraform

I have to say that the Terraform configuration is not complicated and the result will produce a single node cluster with a D2 worker node.


To start the deployment, make sure your machine is configured for Terraform and Azure CLI and run the following Azure CLI commands to connect and select the subscription.

az login
 az account set --subscription azure_subscription_name


After connecting run Terraform with the following configuration file. Note that the cluster will be created inside a new resource group called TF-AKS.

provider "azurerm" {
features {}
resource "azurerm_resource_group" "TF-AKS" {
name = "TF-AKS-resources"
location = "West US"

resource "azurerm_kubernetes_cluster" "TF-AKS" {
name = "aks"
location = azurerm_resource_group.TF-AKS.location
resource_group_name =
dns_prefix = "aks"

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"

identity {
type = "SystemAssigned"

tags = {
Environment = "Production"

output "client_certificate" {
value = azurerm_kubernetes_cluster.TF-AKS.kube_config.0.client_certificate

output "kube_config" {
value = azurerm_kubernetes_cluster.TF-AKS.kube_config_raw