Here I will share my learnings using Terraform at Microsoft Azure.
After installing Terraform the next step is configuring the Terraform access to Azure (you will need azure subscription)
Also you I will be using Azure CLI command, you can fins how to install the Azure CLI here
To enable Terraform to provision resources into Azure, create an Azure AD service principal. The service principal grants your Terraform scripts to provision resources in your Azure subscription.
Having installed your Azure CLI and subscription, loging to you Azure account from your terminal:
az login
If you find connecting issues with your corporate proxy try any of these solutions or [this] (https://blog.jhnr.ch/2017/09/24/use-azure-cli-with-corporate-proxy-server/)
Query the information of you azure subscription
az account list --query "[].{name:name, subscriptionId:id, tenantId:tenantId}"
Set your subscription for you azure cli session
export SUBSCRIPTION_ID=$(az account list --query "[].{subscriptionId:id}")
az account set --subscription="${SUBSCRIPTION_ID}"
Now create the Azure AD service principal
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"
Your appId, password, sp_name, and tenant are returned. Make a note of the appId and password.
To configure Terraform to use your Azure AD service principal, set the following environment variables, which are then used by the Azure Terraform modules.
export ARM_SUBSCRIPTION_ID=your_subscription_id
export ARM_CLIENT_ID=your_appId
export ARM_CLIENT_SECRET=your_password
export ARM_TENANT_ID=your_tenant_id
Continuing at your azure cli session, use the test.tf file and run the Terraform commands. the test.tf will download the azure terraform provider and then it will create a resource group at your subscription.
terraform init
terraform apply
You can apply the terraform destroy command to remove your test resource grupo with terraform.
terraform destroy