DEV Community

Cover image for How to create AKS using Terraform - Part 1

Posted on • Updated on


How to create AKS using Terraform - Part 1

In this article, We will see how to create AKS cluster using Hashicorp Terraform

How to create AKS using Terraform

- How to create AKS using Terraform - Part 1
- How to create AKS using Terraform - Part 2

Azure Kubernetes Service (AKS) is a highly available, secure, and fully managed Kubernetes service of Microsoft Azure.

AKS is a fully managed service from Microsoft that is highly available and secure.

Azure Kubernetes Service (AKS) simplifies deploying a managed Kubernetes cluster in Azure by offloading the operational overhead to Azure. As a hosted Kubernetes service, Azure handles important tasks, like health monitoring and maintenance. Since Kubernetes masters are managed by Azure, we only manage and maintain the agent nodes. Thus, AKS is free; we only pay for the agent nodes within our clusters, not for the masters.


Setting up the Azure account

Before we begin developing clusters and utilizing Terraform, we have to deploy the Azure CLI.

You can locate the respectable documentation on putting in the Azure CLI here.

Terraform Installation

Follow the instructions here to set up Terraform. When you’re done, we need to be in a position to run the terraform command:

terraform -version
Enter fullscreen mode Exit fullscreen mode

Azure Service Principal Creation

We want to create the service principal, for that Kindly run following command in CMD.

az login
Enter fullscreen mode Exit fullscreen mode

Configuring Azure storage to keep Terraform state file

Terraform tracks state locally by means of the terraform.tfstate file. This pattern works well in a standalone environment. However, in a business enterprise environment, we need to track state using Azure storage.

Use below option to create an Azure storage account and container:

Create a storage account

We have created the following resources to create AKS.

  1. Terraform hooked up in the machine
  2. Azure Service Principal – To create the azure k8s
  3. Azure Storage and containers – To keep tfstate file

Before we execute the terraform, We will create a git repository. Once the repository is ready, create following files,


Kindly refer the article for How to create AKS using Terraform - Part 2

Thanks for reading my article till end. I hope you learned something special today. If you enjoyed this article then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box.

Above blog is submitted as part of 'Devtron Blogathon 2022' -
Check out Devtron's GitHub repo - and give a ⭐ to show your love & support.
Follow Devtron on LinkedIn - and Twitter -, to keep yourself updated on this Open Source project.

Top comments (0)