Terraform for Azure is much easier once the cloud side feels familiar. The azurerm provider needs a subscription ID. Almost every resource lives in a resource group. And when you work on your laptop, authentication often starts with an Azure CLI login. If those pieces are still fuzzy, a plan or apply can fail for reasons that look like Terraform problems but are really Azure basics.
This is part 1 of a short Azure for Terraform series. It covers the account, the subscription, resource groups, regions, naming and the CLI, and it shows why each one matters when you later write .tf files.
What this series covers
Later posts are not published yet, so they are listed as upcoming.
- This post. Azure account and free offer, subscription versus tenant versus management groups, resource groups, regions, naming and tags, and Azure CLI login.
- Upcoming. Identity and access, including Microsoft Entra ID, service principals and Azure role based access control. This is what Terraform uses to authenticate beyond a personal CLI login.
- Upcoming. Networking basics, including virtual networks, subnets, network security groups and public IP addresses. Most first Terraform examples start here.
- Upcoming. Compute and storage, including virtual machines, App Service and storage accounts. A storage account is also a common place to keep Terraform remote state.
- Upcoming. Build a small setup in the Azure portal, then recreate the same thing in Terraform. That is the bridge from clicking around to infrastructure as code.
If you already know how to run Terraform in CI, our guide to secure Terraform pipelines with GitHub Actions shows how this later moves off your laptop. For now, stay local and get the Azure foundation right.
Start with an Azure account
You need an Azure account before Terraform can create anything. New customers can sign up for Microsoft’s Azure free account. On the official offer page, that currently includes a $200 credit to use within 30 days, monthly free amounts of more than 20 popular services for 12 months, and monthly free amounts of more than 65 services that stay free. Microsoft says it will not charge the card unless you move to pay as you go pricing. A temporary one dollar (or equivalent) hold can appear during verification and is then removed. Offers can vary by country, and there is a limit of one free account offer per new customer, so check the official terms for your region. You will need a phone number, a credit or debit card that is not prepaid, and a Microsoft account or a GitHub account.
The free account is enough to practice the examples in this series if you delete resources you no longer need and watch the credit in Cost Management. After 30 days, or after the credit is used up, the account and services are disabled unless you move to pay as you go. If you do move, the remaining 12 month and always-free amounts can continue, and you pay only for usage above those amounts.
Subscription, tenant and management groups
Azure is organized in layers. Getting these names straight will save you a lot of confusion later.
A Microsoft Entra tenant is the identity directory. It holds users, groups and apps, and it is the trust boundary for sign-in. An Azure subscription is a billing and management container. Microsoft’s resource management guidance explains that resources and resource groups live inside a subscription, and that the subscription trusts one Entra tenant. One tenant can have many subscriptions. A subscription can be moved between tenants, but it trusts only one tenant at a time.
Management groups sit above subscriptions and let you apply policy, compliance and role assignments across many subscriptions at once. Every subscription under a management group must trust the same Entra tenant. If you have a single personal subscription, you can ignore management groups for now. They start to matter when a company has several subscriptions, such as one for development and one for production.
This matters for Terraform because the azurerm provider works against a subscription. In version 4 of the provider, you must set subscription_id in the provider block, or export the ARM_SUBSCRIPTION_ID environment variable, before you run plan or apply. HashiCorp’s 4.0 upgrade guide says this was made mandatory so Terraform does not silently pick whatever subscription happens to be active in the Azure CLI. That older habit could apply changes to the wrong subscription. Your user login belongs to a tenant. The resources you create belong to a subscription. The next post covers identity in more depth.
Resource groups
A resource group is a container for related Azure resources. Microsoft’s resource group documentation recommends putting resources that share a lifecycle in the same group, so you can deploy, update or delete them together. Delete a resource group and Azure deletes the resources inside it. The group’s location is where Azure stores metadata, not a rule that every resource inside must live in the same region. Resources in one group can sit in different regions, though Microsoft’s Cloud Adoption Framework setup guide still recommends aligning locations with the group when you can.
In Terraform, the resource group is usually the first thing you create. Many resource blocks take a resource_group_name argument, so almost every later resource points back to this container. If you skip this step, you will keep getting errors about a missing group.
Regions
An Azure region is a set of datacenters in a geography, such as India, the United States or Europe. Microsoft currently provides over 70 regions worldwide. The region you pick affects latency for your users, data residency rules, and which resiliency options you get, such as availability zones. Pick a region close to the people who will use the app. If your users are in India, Central India or South India is a reasonable starting point. If they are in the United States, a US region is usually the better default. Also check that the services you need are available there, because not every product ships everywhere at the same time.
In Terraform, this value shows up as location on the resource group and on most resources. Use a consistent location string, and do not change it lightly. On a resource group, changing the location forces Terraform to create a new group.
Naming and tags
Azure resource names cannot be changed after you create them. The Cloud Adoption Framework says you should put only stable information in the name, and use tags for details that might change. A simple pattern looks like rg-demo-dev-centralindia. That starts with Microsoft’s recommended abbreviation for a resource group, then a workload name, an environment and a region. Not every Azure resource allows hyphens, and length limits differ, so check the naming rules for the resource type.
Tags are key-value pairs such as environment = dev or workload = demo. You can tag resources, resource groups and subscriptions, but not management groups. Tags do not inherit automatically, so a tag on the group does not appear on the resources inside it unless you copy it or enforce it with Azure Policy. Do not put secrets in tags. Microsoft stores them as plain text, and they can show up in cost reports, templates and logs. A consistent name and a few honest tags make Terraform plans easier to read, and they help later when you filter costs or write policy.
Install the Azure CLI and log in
The Azure CLI is the command line tool Terraform can use to authenticate when you work on your own machine. Install it from Microsoft’s official install guide for Windows, macOS or Linux. You can also use Azure Cloud Shell in the browser, which already has the CLI. After install, sign in and confirm the active subscription.
az version
az login
az account show --output table
az account list --output table
az account set --subscription "00000000-0000-0000-0000-000000000000"
az account show --output table
If the CLI can open a browser, az login takes you through an interactive sign-in. If it cannot, it gives you a device code and asks you to open https://aka.ms/devicelogin. You can force that flow with az login --use-device-code. Microsoft has required multifactor authentication for Azure CLI sign-in with user identities since September 2025. That requirement does not apply to workload identities such as service principals or managed identities, which we will use in later posts and in CI.
az account set changes the default subscription for CLI commands. It does not replace subscription_id in a Terraform 4.x provider block. Set both, and use the same subscription ID, so the CLI and Terraform point at the same place. This local login is the right way to learn. For a shared pipeline, do not leave a long-lived secret in GitHub. Our Terraform GitHub Actions guide walks through short-lived federated credentials instead, including an Azure login example.
How this looks in Terraform
Once you can log in and you know your subscription ID, a first Terraform file can stay very small. The snippet below is written for azurerm 4.x. HashiCorp’s 4.0 upgrade guide says subscription_id is required for plan and apply, either in the provider block or as ARM_SUBSCRIPTION_ID. The provider documentation also requires a features block. The resource group example follows the official azurerm_resource_group arguments, name and location, with optional tags. Replace the placeholder subscription ID with your own, which you can copy from az account show. After Azure CLI authentication is in place, Terraform can use those credentials for local plan and apply.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4.0"
}
}
}
provider "azurerm" {
features {}
subscription_id = "00000000-0000-0000-0000-000000000000"
}
resource "azurerm_resource_group" "demo" {
name = "rg-demo-dev-centralindia"
location = "Central India"
tags = {
environment = "dev"
workload = "demo"
}
}
After you save this as something like main.tf, the usual flow is terraform init, then terraform plan, then terraform apply. Terraform will use your Azure CLI login, create the resource group in Central India, and attach the tags. If plan fails with a missing subscription ID, you have not set it yet. If it fails with an authentication error, run az login again and confirm az account show points at the same subscription. We will not create networks, virtual machines or a remote state backend in this post. A resource group is enough to prove that the account, the subscription, the region and the CLI login all work together.
What to learn next
You now have the Azure pieces Terraform expects on day one. The next post covers Entra ID, service principals and role based access control, so you can give Terraform an identity of its own instead of relying only on your user login. After that we will cover virtual networks and subnets, then compute and storage, including using a storage account for remote state. The last post will build the same small environment in the portal and in Terraform side by side. If you later provision a container platform, our explainer on Docker versus Kubernetes is a useful companion. You do not need it yet.
Frequently asked questions
Do I need to learn all of Azure before I start Terraform?
No. You need the account, the subscription, resource groups, regions, a simple naming habit and a working Azure CLI login. The rest of this series adds identity, networking, compute and storage, then rebuilds the same setup in Terraform.
What is the difference between a tenant and a subscription?
A Microsoft Entra tenant is the identity directory that holds users, groups and apps. An Azure subscription is the billing and management container where resource groups and resources live. A subscription trusts one tenant, and one tenant can have many subscriptions.
Why does the azurerm provider need a subscription ID?
In version 4 of the provider, HashiCorp requires subscription_id, or the ARM_SUBSCRIPTION_ID environment variable, for plan and apply. That stops Terraform from silently using whichever subscription is currently active in the Azure CLI.
Does az account set replace subscription_id in Terraform?
No. az account set changes the default subscription for Azure CLI commands. In azurerm 4.x you still need to set subscription_id in the provider block or export ARM_SUBSCRIPTION_ID. Use the same ID in both places.
Is the Azure free account enough to practice Terraform?
Yes, for the small examples in this series, if you are a new customer and you stay inside the official offer. Microsoft currently gives new customers a $200 credit for 30 days, plus monthly free amounts of selected services. Delete unused resources and check the official terms for your region.
Can I skip the Azure CLI and use only the portal?
The portal is a good way to look around, and the last post in this series will build the same setup there first. For local Terraform work, a CLI login is still the simplest official authentication method. Later posts cover service principals and federated credentials for pipelines.
Sources
- Microsoft Azure, Create your Azure free account or pay as you go
- Microsoft Learn, Resource management fundamentals in Microsoft Entra ID
- Microsoft Learn, Organize your resources with management groups
- Microsoft Learn, Manage resource groups in the Azure portal
- Microsoft Learn, Organize your Azure resources effectively
- Microsoft Learn, Azure resource abbreviations
- Microsoft Learn, Use tags to organize your Azure resources
- Microsoft Learn, What are Azure regions?
- Microsoft Learn, How to install the Azure CLI
- Microsoft Learn, Sign in with Azure CLI
- Microsoft Learn, Manage Azure subscriptions with the Azure CLI
- Microsoft Learn, Get started with Azure CLI
- Terraform Registry, Azure Resource Manager 4.0 upgrade guide
- Terraform Registry, Authenticating the azurerm provider via the Azure CLI
- Terraform Registry, azurerm_resource_group
- Terraform Registry, azurerm provider documentation





