- Tell Terraform which cloud/provider to talk to (provider block).
- Define what you want to create (resource block).
- Provide details about the resource (arguments).
Minimal example: Create a Resource Group in Azure
This minimal configuration contains the provider, a resource block, and the arguments Terraform needs to create a resource group in Azure.- provider block: configures how Terraform talks to Azure.
- resource block: declares what to create.
- arguments:
nameandlocationdefine the resource properties.
Terraform three-command workflow
After you write HCL, Terraform uses a simple workflow:
Representative outputs you will commonly see are shown below.
Initialize the project (downloads providers):
plan:
terraform validate and terraform fmt here — for now remember that the HCL code declares desired state, and Terraform’s commands make and reconcile those changes.
Provider block details
The provider block configures how Terraform communicates with an external system — in this case Azure via the AzureRM provider.The
features {} block is required by the AzureRM provider and enables provider defaults. You can supply credentials in the provider block (for example subscription_id), but it’s common and recommended to authenticate via environment variables, Azure CLI (az login), or managed identities for automation scenarios.subscription_id embedded (less common for production):
Resource block details
A resource block declares the infrastructure to create. The syntax pattern is:resource "<PROVIDER>_<TYPE>" "<LOCAL_NAME>" { ... }
<PROVIDER>_<TYPE>: the resource type, for exampleazurerm_storage_account.<LOCAL_NAME>: a local reference used inside Terraform configurations (this name is not visible to Azure).
Quick reference: workspace and main.tf
Set up a workspace folder (for examplefirst-code) and add main.tf. You can keep everything in main.tf while learning, and later split into multiple files and modules.
Example main.tf combining provider and resource group:
- Save your files before running Terraform commands (
Ctrl+S/Cmd+S). - From the directory containing
main.tf, runterraform init. This downloads the provider plugin into the.terraformdirectory. - Run
terraform planto preview changes. - Run
terraform applyto create the resources (typeyeswhen prompted, or use-auto-approvefor automation).
terraform init:
terraform plan output:
Getting started in Visual Studio Code
Before you start writing HCL, ensure:- Terraform is installed and available in your
PATH. - You’re authenticated to Azure CLI via
az loginand have a subscription selected (az account show). - Optionally, install the HashiCorp Terraform extension for VS Code to get syntax highlighting and IntelliSense. There are also third-party extensions — only install from trusted sources.

az account show returns account details similar to this (trimmed output):
State file and drift detection
Terraform stores the state of managed resources in the state file (by defaultterraform.tfstate) inside your workspace. This file maps Terraform resources to real-world objects and is essential for planning and updates.
Key points:
- Deleting the state file causes Terraform to “forget” the resources it manages — future plans may attempt to recreate them.
- If a resource is modified outside Terraform (for example, changing tags in the Azure Portal), the next
terraform planwill detect this drift and display the changes needed to reconcile the infrastructure with your code.
terraform plan. Terraform will detect the difference and propose the actions to match the declared configuration.

plan or apply), it compares actual resources in Azure with the local state and the configuration declared in HCL, and then reconciles them according to your code.
Helpful references and next topics
- Official provider documentation:
- azurerm_resource_group: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group
- azurerm_storage_account: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account
- Recommended next topics to learn: variables, outputs, modules, remote state backends, and best practices for structuring Terraform projects.
Tip: Use the official HashiCorp Terraform extension for VS Code to get verified tooling and IntelliSense. If you use third-party extensions, ensure they come from trusted sources.