Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform Upgrade Providers

In an existing Terraform directory:

~ terraform version  
Terraform v0.11.11
+ provider.aws v1.51.0

If I setup a new Terraform directory:

~ terraform version
Terraform v0.11.11
+ provider.aws v1.55.0

How do I upgrade my provider.aws? If I set version = "~> 1.55.0" in the provider "aws" in my .tf file, I get an error:

* provider.aws: no suitable version installed
  version requirements: "~> 1.55.0"
  versions installed: "1.51.0"

I expected to find a terraform update command or something similar. But I can't find that.

Am I not supposed to upgrade the provider? Do I need to delete state, rerun init and then refresh? Or is there a better way?

like image 461
clay Avatar asked Jan 11 '19 22:01

clay


People also ask

How do I update AWS provider version Terraform?

Use terraform init -upgrade command to upgrade the latest acceptable version of each provider. Show activity on this post. Just run terraform init to upgrade AWS plugin version, no need to delete state file. it will only upgrade if you specify the -upgrade option specified by the other answer.

How do I upgrade Terraform workspace?

Update workspace Terraform versionOn the Terraform Cloud workspace settings page, update your workspace's version to 0.13. 7 and save the change. Then, merge your pull request to update the version constraint on your main branch.

What is provider version Terraform?

The terraform block contains the required_providers block, which specifies the provider local name, the source address, and the version. When you initialize this configuration, Terraform will download: Version 3.0. 0 of the random provider. The latest version of the AWS provider that is at greater than 2.0.


3 Answers

There is two solutions to solve this problem:

  1. Just remove the terraform cache rm -fr .terraform and do a terraform init again. This could be dangerous if the Terraform state is in that folder.
  2. There is indeed an -upgrade argument to the init command in order to upgrade provider versions within constraint limits.
like image 74
Quentin Revel Avatar answered Oct 16 '22 19:10

Quentin Revel


Use terraform init -upgrade command to upgrade the latest acceptable version of each provider.

Before Upgrade

ubuntu@staging-docker:~/terraform$ terraform -version
Terraform v0.12.8
+ provider.aws v2.16.0
+ provider.template v2.1.2

Command to upgrade

ubuntu@staging-docker:~/terraform$ terraform init -upgrade
Upgrading modules...
- asg in asg
- ecs in ecs
- lambda in lambda
- lt in lt

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "aws" (hashicorp/aws) 2.27.0...
- Downloading plugin for provider "template" (hashicorp/template) 2.1.2...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.aws: version = "~> 2.27"
* provider.template: version = "~> 2.1"

After Upgrade

ubuntu@staging-docker:~/terraform$ terraform version
Terraform v0.12.8
+ provider.aws v2.27.0
+ provider.template v2.1.2
like image 10
Suraj Singh Rathore Avatar answered Oct 16 '22 19:10

Suraj Singh Rathore


Just run terraform init to upgrade AWS plugin version, no need to delete state file.

like image 3
user2983509 Avatar answered Oct 16 '22 17:10

user2983509