Skip to main content

Terraform providers

All the providers are categorized into 3 types.

  • Official : Managed HashiCorp
  • Verified : Developed by Community or enterprises and verified by HashiCorp
  • Community : Developed by Community or enterprises
tip

Maintain the version specifcations in the terraform configuration

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}

provider "aws" {
region = "us-east-1"
}

Version number syntax:

SyntaxMeaning
>= 3.0Greater than or equal to 3.0
<= 3.0Less than or equal to 3.0
~> 3.0Any version in 3.X range
<=3.0 , >=2.5Any version betweek 2.5 & 3.0 inclusive
  • terraform init will download plugins associated with the providers into .terraform directory.
  • terraform uses .terraform.lock.hcl as the dependency lock file.
  • To upgrade the dependency lock file, run terraform init with upgrade flag
terraform init -upgrade

Mulit Region terraform providers

To handle AWS provider for multiple regions, use alias & provider as attribute in resourece

provider "aws" {
region = "us-east-1"
}

# Additional provider configuration for west coast region
provider "aws" {
alias = "west"
region = "us-west-2"
}

resource "aws_instance" "east_ec2" {
provider = "aws.west"
# ...
}

resource "aws_instance" "west_ec2" {
provider = "aws.west"
# ...
}