Terraform — Provider Versioning

Provider plugins are released separately

while we running terraform -init, if the version number is not specified the latest version of the provider will be installed.

For production, it's always recommended to use a specific version number.

Example:

terraform {

required_providers {

aws = {

source = “hashicorp/aws”

version = “~> 3.0”

}

}

}

In the above example ~>3.0, represents the latest provider which is available under 3.x. below are different types of arguments you can specify

version =”= 2.10" this will install the provider which is 2.10

version =”< = 2.0" this will install the provider which is less than 2.0

version =”> = 2.0, < = 2.3" this will install the provider which is between 2.0 and 2.3

if the specific version is specified, terraform will not install the latest version of the provider.

Once you create a terraform -init

Let's say we run the terraform init with version = “~>2.0”.It will create a file called terraform. lock.hcl , with version and constraints in it. Since ~>2.0 was mentioned, it will get the max version of the provider which is 2.70

main.tf file sample with version ~>2.0
terraform.locl.hcl file with version and constraints

what if, if you want to upgrade the provider by changing the version number in the main.tf file

and try to run terraform init

error when you run terraform.init

you will get below error :

Error: Failed to query available provider packages

│ Could not retrieve the list of available versions for provider hashicorp/aws: locked provider registry.terraform.io/hashicorp/aws 2.70.0 does not match configured version constraint ~> 3.0; must use
│ terraform init -upgrade to allow selection of new versions

to overcome this, either delete the terraform. lock.hcl file or use terraform init -upgarde

--

--

--

Data Engineering Manager @Comcast

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Making of Anchorage

INDIA’S first ever #TESTATHON — 2016 Awaited Procurement of Milestones!

My Vision: Heptabase

Delegates in C++// Polos

How can we display HMS Banner Ads After Successful login using HMS Account Kit ?

3 Best Alternate Cloud Service Platforms (Not — Google, AWS, Microsoft)

Migrate all media files Django into S3

How Our Fearless Mobile Developers Rebuilt Our Apps from Scratch

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Santosh Dadisetti

Santosh Dadisetti

Data Engineering Manager @Comcast

More from Medium

Terraform Modules : Package and Reuse

How to Deploy Amazon WorkSpaces in AWS using Terraform

The BEST way to structure your Terraform projects!

Terraform Basics