Skip to main content
🎤 Luca Berton is speaking at Red Hat Summit & KubeCon EU 2026!Learn more →
Back to Blog

Terraform Providers Deep Dive

Terraform providers for multi-cloud. Configuration, version pinning, aliases for multi-region, and debugging provider issues.

Luca BertonFebruary 5, 20261 min read

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

hcl
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

hcl
# 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.

bash
# Update lock file after changing versions
terraform init -upgrade

# View installed versions
terraform providers

Provider Aliases (Multi-Region)

hcl
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
  }
}
Related Course

Master this topic with hands-on labs

Go beyond reading — build real projects in sandboxed environments with expert video guidance.

Browse Courses →

Authentication

AWS

hcl
# 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

hcl
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

hcl
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

ProviderUse Case
hashicorp/awsAWS infrastructure
hashicorp/googleGCP infrastructure
hashicorp/azurermAzure infrastructure
hashicorp/kubernetesK8s resources
hashicorp/helmHelm chart deployments
cloudflare/cloudflareDNS, CDN, WAF
integrations/githubRepos, teams, branch protection
hashicorp/vaultSecrets management
hashicorp/randomRandom passwords, pet names
hashicorp/nullProvisioners, triggers
hashicorp/localLocal files
Stay Updated

Get weekly IT automation tips

Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.

Subscribe Free →

Provider Debugging

bash
# 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 init

Lock File

The .terraform.lock.hcl file pins exact provider versions and checksums:

hcl
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.

Share this article
LB
Luca Berton

Docker Captain, IT automation expert, Red Hat Summit & KubeCon speaker. Building hands-on education for DevOps engineers at CopyPasteLearn.

Related Articles

Explore topics

Browse more articles on the topics covered here.