Terraform升级提供商

时间:2019-01-11 22:46:39

标签: terraform terraform-provider-aws

在现有Terraform目录中:

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

如果我设置了新的Terraform目录:

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

如何升级我的provider.aws?如果我在version = "~> 1.55.0"文件的provider "aws"中设置了.tf,则会收到错误消息:

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

我希望找到一个terraform update命令或类似的命令。但是我找不到。

我不应该升级提供商吗?我需要删除状态,重新运行init,然后重新运行refresh吗?还是有更好的方法?

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:3)

使用 terrain init -upgrade 命令升级每个提供商的最新可接受版本。

升级前

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

升级命令

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"

升级后

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

答案 2 :(得分:1)

有两种解决此问题的方法:

  1. 只需删除地形缓存rm -fr .terraform,然后再次执行terraform init。如果Terraform状态位于该文件夹中,则可能很危险。
  2. init命令确实有一个-upgrade参数,以便在约束范围内升级提供程序版本。