Terraform with Azure Integration
By Roshan | 23nd Aug 2025

Introduction
In today’s digital era, cloud computing has become the backbone of modern IT infrastructure. Organizations are rapidly shifting from traditional manual provisioning to automated cloud deployments. The reason is simple: automation saves time, reduces errors, and ensures consistency.
One of the most widely adopted tools for automation in cloud environments is Terraform, developed by HashiCorp. Terraform follows the principle of Infrastructure as Code (IaC), where infrastructure can be defined and managed using human-readable configuration files.
Among the most fundamental building blocks of Terraform are Providers and Resources. Providers act as the communication bridge between Terraform and cloud or third-party services, while resources represent the actual infrastructure components being created or managed. Without providers and resources, Terraform would not be able to function.
This article provides a detailed understanding of providers and resources, their relationship, how they work together, and real-world examples of how they are used in cloud deployments.
1. What are Providers in Terraform?
Providers in Terraform are plugins that enable Terraform to interact with cloud platforms, SaaS applications, or other APIs. They contain the logic required to translate Terraform configurations into API calls to the target platform.
- Role of Providers: They act as the “drivers” that connect Terraform to external systems.
- Examples of Providers:
- aws for Amazon Web Services
- azurerm for Microsoft Azure
- google for Google Cloud Platform
- kubernetes for Kubernetes clusters
- github for GitHub repositories
Each provider is developed and maintained either by HashiCorp, the cloud vendor, or the open-source community.
Example:
provider “aws” {
region = “us-east-1”
}
This tells Terraform to use the AWS provider and operate in the us-east-1 region.
2. Types of Providers
Providers can be broadly categorized into two types:
- Cloud Providers: AWS, Azure, GCP, Oracle Cloud, Alibaba Cloud.
- Service Providers: Datadog, GitHub, Okta, Kubernetes, Cloudflare, etc.
This means Terraform is not limited to cloud infrastructure alone but can also manage services like monitoring, DNS management, and version control.
3. What are Resources in Terraform?
If providers are the bridge, resources are the actual building blocks. A resource in Terraform represents a component of infrastructure, such as:
- A virtual machine in AWS (aws_instance)
- A storage bucket in Google Cloud (google_storage_bucket)
- A database in Azure (azurerm_sql_database)
- A load balancer, VPC, or even DNS records
Resources are defined in resource blocks within Terraform configuration files.
Example:
resource “aws_instance” “web” {
ami = “ami-0c55b159cbfafe1f0”
instance_type = “t2.micro”
tags = {
Name = “WebServer”
}
}
Here, Terraform provisions an EC2 instance using the aws_instance resource.
4. Relationship Between Providers and Resources
Providers and resources always work together.
- A provider defines which platform Terraform interacts with.
- A resource defines what Terraform will create or manage in that platform.
For example, if you declare an AWS provider, Terraform can then use AWS-specific resources like EC2, S3, VPC, or RDS.
Example with Azure:
provider “azurerm” {
features {}
}
resource “azurerm_resource_group” “example” {
name = “terraform-rg”
location = “East US”
}
- Provider: azurerm (Azure Resource Manager)
- Resource: azurerm_resource_group (Resource Group in Azure)
5. Multiple Providers in One Configuration
Terraform allows multiple providers in a single project, enabling multi-cloud deployments or integration with different services at the same time.
Example:
provider “aws” {
region = “us-east-1”
}
provider “azurerm” {
features {}
}
resource “aws_s3_bucket” “bucket” {
bucket = “terraform-bucket-demo”
}
resource “azurerm_resource_group” “rg” {
name = “multi-cloud-rg”
location = “East US”
}
This single configuration creates resources in both AWS and Azure, showing the flexibility of Terraform.
6. Resource Arguments and Attributes
Each resource in Terraform has two important aspects:
- Arguments → The input values you specify when defining a resource (e.g., AMI ID, instance type).
- Attributes → The output values that Terraform provides after creating the resource (e.g., instance ID, public IP).
Example:
resource “aws_instance” “web” {
ami = “ami-0c55b159cbfafe1f0”
instance_type = “t2.micro”
}
output “instance_ip” {
value = aws_instance.web.public_ip
}
- Arguments: ami, instance_type
- Attribute: public_ip (generated after the resource is created)
7. Data Sources in Terraform
In addition to creating resources, Terraform can also fetch existing infrastructure details using data sources.
This is useful when you want to use existing AMIs, networks, or databases without creating new ones.
Example:
data “aws_ami” “ubuntu” {
most_recent = true
owners = [“099720109477”] # Canonical
}
resource “aws_instance” “web” {
ami = data.aws_ami.ubuntu.id
instance_type = “t2.micro”
}
Here, Terraform queries AWS for the latest Ubuntu AMI and uses it to create an EC2 instance.
8. Real-World Example (Connecting Multiple Resources)
In real deployments, resources are often connected. Let’s consider an example of creating an EC2 instance with a security group:
provider “aws” {
region = “us-east-1”
}
# Security Group
resource “aws_security_group” “web_sg” {
name = “web_sg”
description = “Allow HTTP traffic”
ingress {
from_port = 80
to_port = 80
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}
egress {
from_port = 0
to_port = 0
protocol = “-1”
cidr_blocks = [“0.0.0.0/0”]
}
}
# EC2 Instance
resource “aws_instance” “web” {
ami = “ami-0c55b159cbfafe1f0”
instance_type = “t2.micro”
security_groups = [aws_security_group.web_sg.name]
tags = {
Name = “TerraformWebServer”
}
}
- The provider is AWS.
- The resources include a security group and an EC2 instance.
- The EC2 instance depends on the security group.
Terraform understands these dependencies automatically and creates the resources in the correct order.
9. Best Practices for Providers and Resources
- Pin Provider Versions – Always specify provider versions to avoid breaking changes.
- terraform {
- required_providers {
- aws = {
- source = “hashicorp/aws”
- version = “~> 5.0”
- }
- }
- }
- Use Meaningful Resource Names – Helps in readability and collaboration.
- Outputs for Important Values – Always export attributes like public IPs, DNS names, or resource IDs for reuse.
- Use Data Sources When Possible – Avoid hardcoding values; fetch dynamic data instead.
- Follow Cloud Provider Limits – Ensure that the resource definitions respect quotas and naming conventions.
Conclusion
Providers and resources are the foundation of Terraform.
- Providers connect Terraform to external services, whether it’s a cloud platform or a third-party API.
- Resources represent the actual infrastructure components that Terraform manages.
- By combining providers, resources, arguments, attributes, and data sources, we can model infrastructure in a clear, consistent, and reusable way.
Understanding providers and resources is essential before moving to more advanced Terraform concepts such as modules, workspaces, state management, and remote backends.
By mastering these two concepts, you gain the ability to provision reliable, repeatable, and scalable infrastructure across multiple platforms with ease.