Skip to content

Terraform AWS Provider

Providers are plugins that allow Terraform to interact with cloud platforms, SaaS providers, and other APIs. For AWS, we use the hashicorp/aws provider.

image.png

  • Terraform Core: The main Terraform binary that parses configuration and manages state
  • Provider Version: Individual plugins that communicate with specific APIs (AWS, Azure, Google Cloud, etc.)
  • They have independent versioning and release cycles
  • Compatibility: Ensure provider works with your Terraform version
  • Stability: Pin to specific versions to avoid breaking changes
  • Features: New provider versions add support for new AWS services
  • Bug Fixes: Updates often include important security and bug fixes
  • Reproducibility: Same versions ensure consistent behavior across environments

Use version constraints to specify acceptable provider versions:

  • = 1.2.3 - Exact version
  • >= 1.2 - Greater than or equal to
  • <= 1.2 - Less than or equal to
  • ~> 1.2 - Pessimistic constraint (allow patch releases)
  • >= 1.2, < 2.0 - Range constraint
  1. Always specify provider versions
  2. Use pessimistic constraints for stability
  3. Test provider upgrades in development first
  4. Document version requirements in your README
  5. Use terraform providers lock command for consistency
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.1"
}
}
}