Terraform 上出现“无效的旧提供商地址”错误

2024-02-27

我正在尝试使用 terraform v0.14.3 部署 bitbucket 管道以在谷歌云中创建资源。运行 terraform 命令后,管道失败并出现以下错误:

Error: Invalid legacy provider address

This configuration or its associated state refers to the unqualified provider
"google".

You must complete the Terraform 0.13 upgrade process before upgrading to later
versions.

我们将本地版本的 terraform 更新为 v.0.13.0,然后运行:terraform 0.13upgrade如本指南中所引用:https://www.terraform.io/upgrade-guides/0-13.html https://www.terraform.io/upgrade-guides/0-13.html。生成了一个 versions.tf 文件,要求 terraform 版本 >=0.13,我们所需的提供程序块现在如下所示:

terraform {
  backend "gcs" {
    bucket      = "some-bucket"
    prefix      = "terraform/state"
    credentials = "key.json" #this is just a bitbucket pipeline variable
  }
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 2.20.0"
    }
  }
}
provider "google" {
  project     = var.project_ID
  credentials = "key.json"
  region      = var.project_region
}

启动 bitbucket 管道时我们仍然遇到相同的错误。有谁知道如何克服这个错误?提前致谢。


Solution

如果您使用的是较新版本的 Terraform,例如v0.14.x, 你应该:

  1. use the replace-provider子命令

    terraform state replace-provider \
    -auto-approve \
    "registry.terraform.io/-/google" \
    "hashicorp/google"
    
    #=>
    
    Terraform will perform the following actions:
    
      ~ Updating provider:
        - registry.terraform.io/-/google
        + registry.terraform.io/hashicorp/google
    
    Changing x resources:
    
      . . .
    
    Successfully replaced provider for x resources.
    
  2. 再次初始化 Terraform:

    terraform init
    
    #=>
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Reusing previous version of hashicorp/google from the dependency lock file
    - Using previously-installed hashicorp/google vx.xx.x
    
    Terraform has been successfully initialized!
    
    You may now begin working with Terraform. Try . . .
    

    This should请注意安装提供程序。

解释

Terraform 一次仅支持从一项主要功能升级进行升级。您的旧状态文件很可能是使用早于以下版本的版本创建的v0.13.x.

如果您没有运行apply在升级 Terraform 版本之前执行命令,您可能会遇到此错误:从v0.13.x to v0.14.x was not完全的。

您可以找到更多信息here https://discuss.hashicorp.com/t/unqualified-provider-aws/18554/5.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Terraform 上出现“无效的旧提供商地址”错误 的相关文章

随机推荐