How to create Azure Kubernetes Service using Terraform - Part 1
Tags: terraform, azure, aks, kubernetes
Published: 2022-05-18 18:51:58

In this article, We will see how to create AKS cluster using Hashicorp [Terraform](https://www.terraform.io/)


## How to create Azure Kubernetes Service using Terraform

**- [How to create Azure Kubernetes Service using Terraform - Part 1](https://dev.to/kcdchennai/how-to-create-azure-kubernetes-service-using-terraform-part-1-3mcf)**
**- [How to create Azure Kubernetes Service using Terraform - Part 2](https://dev.to/kcdchennai/how-to-create-azure-kubernetes-service-using-terraform-part-2-56mo)**



Azure Kubernetes Service (AKS) is a highly available, secure, and fully managed [Kubernetes](https://kubernetes.io/) 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.



## Pre-requisites

## 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](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).


## Terraform Installation

Follow the [instructions here](https://learn.hashicorp.com/tutorials/terraform/install-cli) to set up Terraform. When you’re done, we need to be in a position to run the terraform command:


```
terraform -version
```

## Azure Service Principal Creation

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


```
az login
```


## 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](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal)



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,

- provider.tf
- main.tf
- variables.tf
- outputs.tf

Kindly refer the article for [How to create Azure Kubernetes Service using Terraform - Part 2](https://dev.to/kcdchennai/how-to-create-azure-kubernetes-service-using-terraform-part-2-56mo)


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.