Terraform Azure Provider:
The Terraform Azure Provider (officially known as azurerm) is a plugin developed by HashiCorp and maintained in close partnership with Microsoft. It allows you to define, provision, and manage Microsoft Azure infrastructure using Infrastructure as Code (IaC).
Key Highlights
- Declarative Approach: Instead of clicking through the Azure Portal or writing complex scripts, you specify the end state of your infrastructure in human-readable HashiCorp Configuration Language (HCL). Terraform figures out how to build or update it.
- Broad Azure Support: Supports hundreds of Azure services from basic building blocks like Virtual Machines, Resource Groups, VNet/Subnets, and others to managed services like Azure Kubernetes Service (AKS), Azure SQL, and App Services.
- Lifecycle & State Management: Tracks the real-world state of your Azure resources against your code. It helps you safely preview changes using terraform plan before actually creating, updating, or deleting resources with terraform apply.
How to connect Azure Provider in Terraform.
- Prepare the environment; have your folder created, open VS code and choose the folder you are going to work with.
- Inside VS code and on the folder, you are going to use, right click and create a file named main.tf
- Specify azurerm as the provider with the following code:

- Key in terraform, specify the provider then add the source that’s hashicorp/azure (hashicorp being the terraform and azure as your provider there). You add the version you are using.
- Then provider “azurerm”
- Features: that’s the required block for Azure provider settings.
- Open integrated terminal and type: “terraform init” to initializes terraform and create the provider.

- terraform fmt (format) – shows the number of files you have created and, in our case, its main.tf file.
- terraform validate shows the configuration we’ve done so far is valid and showing success.
To be able to connect to Azure, we will need to install Azure CLI onto our machine.
- Open PowerShell and run the script:
winget install --exact --id Microsoft.AzureCLI
Choose one suitable for your machine before you run it. Either mac or windows.
- Azure CLI is already installed: checked the version with az version
After the Azure CLI installation, we will need to log into Azure to connect our terraform.
- On your terminal type, az login.
- A pop-up browser will appear, key in where the account, you’re going to use from the prompt
- Enter your azure credentials to connect.
- After authenticating your credentials, return to the terminal and select the appropriate subscription.

Now the environment is set, let’s create something in Azure.
- Create Azure resource group and add a tag to the group.
✓ Resource “azurerm_resource_group”
✓ Resource group name.
✓ Location of the resource group
✓ Tag addition to the resource group. - Once you are done hit back to the terminal and run these commands;
✓ terraform plan: This shows all the resources terraforms are about to build.
✓ terraform apply: Terraform will perform the actions described above and only “yes” will be accepted to approve it. - Check the terraform statefile to confirm the resources terraform built.
- Also, we will confirm all the resources deployed inside the azure portal.




Now let’s hit back onto the azure portal.

On the resource manager, resource group we’re having “ernest_rg” being created.
Also, a tag has been created for the resource group “ernest_rg” with environment “dev”.

- Finally, terraform destroy is there to help you delete all resources at once inside the terminal.

- All managed infrastructure will be deleted, only “yes” will be accepted to confirm it.
Click on the link below from Microsoft to install Azure CLI onto your machine👇
