【问题标题】:Terraform Upgrade ProvidersTerraform 升级提供商
【发布时间】:2019-06-06 21:04:51
【问题描述】:

在现有的 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?如果我在.tf 文件中的provider "aws" 中设置version = "~> 1.55.0",则会收到错误消息:

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

我希望找到terraform update 命令或类似的东西。但我找不到。

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

【问题讨论】:

    标签: terraform terraform-provider-aws


    【解决方案1】:

    解决这个问题有两种解决方案:

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

    【讨论】:

      【解决方案2】:

      使用 terraform 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
      

      【讨论】:

        【解决方案3】:

        只需运行terraform init即可升级AWS插件版本,无需删除状态文件。

        【讨论】:

        • 只有在你指定另一个答案指定的-upgrade选项时才会升级。
        猜你喜欢
        • 2021-11-04
        • 2021-02-04
        • 2023-01-19
        • 1970-01-01
        • 2021-03-27
        • 2019-04-06
        • 2021-04-19
        • 2017-04-12
        • 1970-01-01
        相关资源
        最近更新 更多