clay
clay

Reputation: 20440

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?

Upvotes: 21

Views: 40692

Answers (3)

Suraj Singh Rathore
Suraj Singh Rathore

Reputation: 1192

terraform init -upgrade

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

Upvotes: 33

Quentin Revel
Quentin Revel

Reputation: 1478

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.

Upvotes: 26

user2983509
user2983509

Reputation: 232

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

Upvotes: 1

Related Questions