Let's learn Terraform : Part 2 How to connect Azure subscription to Terraform?
How to connect Azure subscription to Terraform?
In the previous article we have seen What is Terraform and how to install it. We also ran few simple commands for verification.
In this article we will see how we can connect Azure subscription to Terraform so that will be able to create Azure resources using the Terraform scripts.
As we have configured Powershell ISE to execute Terraform scripts in previous article we will continue using Powershell ISE itself in this article as well.
We first need to install Azure CLI which stands for Azure command-line interface, this allows us to connect to Azure from windows server and to execute Terraform scripts.
There are multiple ways to install Azure CLI as described in this MS article . Here I’m using “WinGet“ method
Open Powershell ISE as an administrator and execute the below command. Make sure you copy the entire command before executing
winget install --exact --id Microsoft.AzureCLI --accept-source-agreements
It will start installing
It get’s installed successfully if there are no issues.
Once Azure CLI installation is successful run the below command in Powershell ISE
az login
You should receive error like below because we have not linked our Azure subscription yet
A pop-up window will open automatically to login to our Azure subscription. It will ask us to provide the credentials
provide all the details accordingly if Azure subscription is linked successfully we should see below output which will have details like subscription name, ID and so on.
Once the account is connected successfully run the below command
az account show
and it should show details of your connected Azure subscription account
This confirms we are now connected to Azure and can now create-modify-delete resources in the Azure Subscription we connected.
In the next article we will try to run a simple Terraform script to create a Azure resource.
Thanks VV!!