(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to Create an Azure Resource Group with Terraform

João Barros 06 de July de 2026 3 min read

Terraform lets you create infrastructure on Azure in a repeatable way, describing what you want in text files instead of clicking around the portal. Creating an Azure Resource Group with Terraform is the first step to automating resources: the group acts as a logical "container" that gathers and organizes everything you provision next. It's also the ideal way to learn the Terraform workflow.

Prerequisites

  • An active Azure subscription (the free tier is enough).
  • Terraform installed (version 1.0 or later).
  • The Azure CLI installed, for authentication.
  • A text editor (for example, VS Code).

Step 1: Authenticate to Azure

Terraform needs permission to talk to Azure. The simplest way is to sign in with the Azure CLI: Terraform reuses those credentials automatically. In production you'd use a service principal instead, but for learning, az login is more than enough.

az login
az account set --subscription "NOME_OU_ID_DA_SUBSCRICAO"

Step 2: Create the configuration file

Create a new folder and, inside it, a file called main.tf. Start by declaring the azurerm provider, which tells Terraform you'll be working with Azure. The features {} block is required, even if left empty.

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }
}

provider "azurerm" {
  features {}
}

Step 3: Define the Resource Group

Still in main.tf, add a resource block of type azurerm_resource_group. Give it an internal name (here, rg) and set the name and location — the region where the group will live.

resource "azurerm_resource_group" "rg" {
  name     = "rg-tutorial-bconcepts"
  location = "West Europe"
}
Tip: pick the location closest to your users to reduce latency and, often, cost.

Step 4: Initialize Terraform

Open the terminal in the project folder and run terraform init. This command downloads the azurerm provider and prepares the working folder.

terraform init

Step 5: Review the plan and apply

With terraform plan you see what will be created, without changing anything. If you agree, terraform apply creates the Resource Group on Azure. Type yes when prompted for confirmation. In the plan, each line with a + represents a resource that will be created — you should see exactly one.

terraform plan
terraform apply

Step 6: Reference the group in another resource

The great advantage of Terraform is linking resources together. To see this in action, add a Storage Account that uses the Resource Group you created. Notice how resource_group_name and location point to the previous block instead of repeating the values by hand.

resource "azurerm_storage_account" "sa" {
  name                     = "stbconcepts0706"
  resource_group_name      = azurerm_resource_group.rg.name
  location                 = azurerm_resource_group.rg.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

output "storage_account_url" {
  value = azurerm_storage_account.sa.primary_blob_endpoint
}

If you run terraform apply again, Terraform creates only the new resource and prints the output at the end. The Storage Account name must be globally unique and can only contain lowercase letters and numbers.

Check the result

Confirm the group was created in two ways. In the terminal, use the Azure CLI; in the portal, search for "Resource groups". If the name shows up, everything went well. You can also open the terraform.tfstate file, where Terraform stores the current state of your infrastructure.

az group show --name "rg-tutorial-bconcepts" --output table

Conclusion

In just a few steps you went from an empty folder to real infrastructure on Azure, defined as code and easy to repeat. When you no longer need the resources, run terraform destroy to delete them and avoid costs. What will be the next resource in your main.tf — a virtual network or a database?