What is a Provider?
A provider is the plugin that lets Terraform talk to a platform:
Terraform
↓
Provider
↓
Cloud Platform
Examples: AWS, Azure, GCP, Kubernetes, GitHub.
Basic AWS provider
provider "aws" {
region = "ap-south-1"
}Provider versioning
Pin the provider in a terraform block so everyone on the team gets a compatible version:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}~> 5.0 allows patch/minor updates within the 5.x line while blocking a jump to 6.x.
Multiple providers (aliases)
One configuration can target several regions by giving additional providers an alias:
provider "aws" {
region = "ap-south-1"
}
provider "aws" {
alias = "singapore"
region = "ap-southeast-1"
}Deploy to Mumbai (default provider)
resource "aws_instance" "mumbai" {
ami = "ami-xxxxxxxx"
instance_type = "t3.micro"
}Deploy to Singapore (aliased provider)
resource "aws_instance" "singapore" {
provider = aws.singapore
ami = "ami-xxxxxxxx"
instance_type = "t3.micro"
}AMI IDs are region-specific. Use an AMI that exists in the target region.
Without provider = aws.singapore, the resource uses the default (unaliased) AWS provider.