Providers are plugins that let Terraform interact with APIs — AWS, Azure, GCP, Kubernetes, GitHub, Cloudflare, and hundreds more. Every resource in Terraform belongs to a provider.
Provider Configuration
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.30"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
required_version = ">= 1.8"
}
provider "aws" {
region = var.aws_region
default_tags {
tags = {
ManagedBy = "terraform"
Environment = var.environment
}
}
}Version Constraints
# Exact version
version = "5.40.0"
# Minimum version
version = ">= 5.0"
# Pessimistic constraint (5.x only, no 6.0)
version = "~> 5.0"
# Range
version = ">= 5.0, < 6.0"Always pin provider versions. A new major version can break your infrastructure.
# Update lock file after changing versions
terraform init -upgrade
# View installed versions
terraform providersProvider Aliases (Multi-Region)
provider "aws" {
region = "eu-west-1"
alias = "ireland"
}
provider "aws" {
region = "us-east-1"
alias = "virginia"
}
# Default provider (no alias) for most resources
provider "aws" {
region = "eu-west-1"
}
# Use alias for specific resources
resource "aws_s3_bucket" "logs" {
provider = aws.virginia
bucket = "my-logs-us-east-1"
}
# CloudFront requires us-east-1 for certificates
resource "aws_acm_certificate" "cdn" {
provider = aws.virginia
domain_name = "cdn.example.com"
}
# Pass provider to module
module "dr_backup" {
source = "./modules/backup"
providers = {
aws = aws.virginia
}
}Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Authentication
AWS
# Option 1: Environment variables (recommended for CI/CD)
# AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
# Option 2: Shared credentials file
provider "aws" {
region = "eu-west-1"
profile = "production"
}
# Option 3: Assume role
provider "aws" {
region = "eu-west-1"
assume_role {
role_arn = "arn:aws:iam::123456789012:role/terraform"
session_name = "terraform-deploy"
}
}
# Option 4: OIDC (GitHub Actions)
provider "aws" {
region = "eu-west-1"
# Uses OIDC token from GitHub Actions
}Kubernetes
provider "kubernetes" {
# From kubeconfig
config_path = "~/.kube/config"
config_context = "production"
}
# Or from EKS
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.cluster.token
}Multi-Cloud
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}
}
# App on AWS
resource "aws_instance" "app" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.medium"
}
# DNS on Cloudflare
resource "cloudflare_record" "app" {
zone_id = var.cloudflare_zone_id
name = "app"
content = aws_instance.app.public_ip
type = "A"
proxied = true
}
# Backup storage on GCP
resource "google_storage_bucket" "backup" {
name = "my-backup-bucket"
location = "EU"
}Useful Providers
| Provider | Use Case |
|---|---|
hashicorp/aws | AWS infrastructure |
hashicorp/google | GCP infrastructure |
hashicorp/azurerm | Azure infrastructure |
hashicorp/kubernetes | K8s resources |
hashicorp/helm | Helm chart deployments |
cloudflare/cloudflare | DNS, CDN, WAF |
integrations/github | Repos, teams, branch protection |
hashicorp/vault | Secrets management |
hashicorp/random | Random passwords, pet names |
hashicorp/null | Provisioners, triggers |
hashicorp/local | Local files |
Get weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Provider Debugging
# Enable debug logging
TF_LOG=DEBUG terraform plan
# Provider-specific logging
TF_LOG_PROVIDER=DEBUG terraform apply
# Check provider cache
ls -la .terraform/providers/
# Force reinstall
terraform init -upgrade
rm -rf .terraform/providers/
terraform initLock File
The .terraform.lock.hcl file pins exact provider versions and checksums:
provider "registry.terraform.io/hashicorp/aws" {
version = "5.40.0"
constraints = "~> 5.0"
hashes = [
"h1:abc123...",
"zh:def456...",
]
}Always commit .terraform.lock.hcl to Git. It ensures everyone uses identical provider versions.
What's Next?
Our Terraform for Beginners course covers providers, authentication, and multi-cloud patterns across 15 hands-on lessons. First lesson is free.
---
Ready to go deeper? Check out our hands-on course: Terraform for Beginners — practical exercises you can follow along on your own machine.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Terraform AWS Exercises for Practice
Hands-on Terraform AWS exercises from beginner to advanced. Practice EC2, S3, VPC, RDS provisioning with real infrastructure.
Terraform Course: What You Learn
What a Terraform course teaches you. Skills, exercises, AWS provisioning, and career benefits of learning Terraform for IaC.
Terraform State Management Guide
Master Terraform state management. Remote backends, state locking, import commands, state moves, and disaster recovery procedures.
Terraform Security Practices
Secure your Terraform workflows — manage secrets, control access, encrypt state, and implement policy-as-code for safe infrastructure deployments.
Terraform State Management
Understand Terraform state — how it tracks resources, why it's critical, and best practices for remote state, locking, and team workflows.
Terraform Testing with Terratest
Terratest lets you write automated tests for Terraform infrastructure using Go. Learn how to test Terraform modules, validate cloud resources, and integrate.
Explore topics
Browse more articles on the topics covered here.