接收错误';旧版提供程序地址无效';在Bitbucket管道中使用Terraform

接收错误';旧版提供程序地址无效';在Bitbucket管道中使用Terraform,terraform,bitbucket-pipelines,terraform-provider-gcp,Terraform,Bitbucket Pipelines,Terraform Provider Gcp,我正在尝试使用terraform v0.14.3部署一个bitbucket管道,以在google云中创建资源。管道发生故障,出现错误: 错误:旧版提供程序地址无效 此配置或其关联状态引用了不合格的提供程序 “谷歌”。 在升级到更高版本之前,必须完成Terraform 0.13升级过程 版本 我们将terraform的本地版本更新为v.0.13.0,然后运行:terraform 0.13升级,如本指南所述:。生成了一个versions.tf文件,要求terraform version>=0.13,

我正在尝试使用terraform v0.14.3部署一个bitbucket管道,以在google云中创建资源。管道发生故障,出现错误:

错误:旧版提供程序地址无效 此配置或其关联状态引用了不合格的提供程序 “谷歌”。 在升级到更高版本之前,必须完成Terraform 0.13升级过程 版本

我们将terraform的本地版本更新为v.0.13.0,然后运行:
terraform 0.13升级
,如本指南所述:。生成了一个versions.tf文件,要求terraform version>=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管道时仍然会遇到相同的错误。有人知道如何克服这个错误吗?提前感谢。

当您处于TF13状态时,是否至少为正在运行的项目应用了一次状态

根据TF文件:

在0.14中没有自动更新命令(单独)(与0.13中相同)。升级的唯一方法是在将TF13移动到14时,在命令下对项目至少强制一次状态


您也可以在项目目录中尝试terraform init。

解释

这是因为Terraform一次只支持一个主要功能升级。您案例中较旧的状态文件很可能是使用0.13版本之前的版本编写的,如果您没有使用0.13版本运行
terraform apply
,则会出现此错误,因为升级到0.13的过程尚未完成。如果您运行它(如上面的回答中所解释的),它可能已经解决了

解决方案

  • 此时(即使用terraform 0.14.x),您可以使用
    替换提供程序
    命令
  • 现在再次初始化,这将负责安装提供程序:

  • 有关此问题的更多信息,请参见。

    我们今天在操作环境中遇到了类似的问题。我们成功地完成了
    terraform 0.13升级
    命令。这确实引入了一个
    versions.tf
    文件

    但是,使用此设置仍无法执行
    terraform init
    ,并弹出以下错误:

    Error: Invalid legacy provider address
    
    州文件中的进一步调查显示,对于某些资源,提供程序块未更新。因此,我们必须运行以下命令来完成升级过程

    terraform state replace-provider "registry.terraform.io/-/google" "hashicorp/google"
    


    EDIT部署到下一个环境表明这是由条件资源引起的。为了方便地启用/禁用某些资源,我们利用
    count
    属性并使用0或1。对于
    count=0
    的资源,在Terraform 0.13中没有改变,提供者没有更新。

    在我们的例子中,我们在aws上,并且有类似的错误

    。。。
    错误:旧版提供程序地址无效
    此配置或其关联状态引用了不合格的提供程序
    “aws”。
    
    要解决的步骤是通过再次运行
    terraforminit
    ,检查警告并最终使用以下方法更新statefile来确保语法得到升级

    #更新状态文件中的提供程序
    地形状态替换提供程序--/aws hashicorp/aws
    #雷尼特
    地形初始
    
    针对ops问题,如果问题仍然存在,请验证是否可以从本地和管道访问铲斗位置。还要验证正在管道中运行的terraform版本。根据配置,远程状态文件可能是/无法更新。

    我的案例是这样的

    Error: Invalid legacy provider address
    
    This configuration or its associated state refers to the unqualified provider
    "openstack".
    
    You must complete the Terraform 0.13 upgrade process before upgrading to later
    versions.
    
    为了解决这个问题

    remove the .terraform folder
    
    执行以下命令

    terraform state replace-provider -- -/openstack terraform-provider-openstack/openstack
    
    执行此命令后,您将看到下面的打印,输入
    yes

    Terraform will perform the following actions:
    
      ~ Updating provider:
        - registry.terraform.io/-/openstack
        + registry.terraform.io/terraform-provider-openstack/openstack
    
    Changing 11 resources:
    
      openstack_compute_servergroup_v2.kubernetes_master
      openstack_networking_network_v2.kube_router
      openstack_compute_instance_v2.kubernetes_worker
      openstack_networking_subnet_v2.internal
      openstack_networking_subnet_v2.kube_router
      data.openstack_networking_network_v2.external_network
      openstack_compute_instance_v2.kubernetes_etcd
      openstack_networking_router_interface_v2.internal
      openstack_networking_router_v2.internal
      openstack_compute_instance_v2.kubernetes_master
      openstack_networking_network_v2.internal
    
    Do you want to make these changes?
    Only 'yes' will be accepted to continue.
    
    Enter a value: yes
    
    Successfully replaced provider for 11 resources.
    

    另外,我安装了Terraform0.14.6,但状态似乎停留在0.12。在我的例子中,我有3个参考是关闭的,这篇文章帮助我确定了哪些参考(在“州要求的提供者”中的所有条目)在链接中有一个-。 我通过为每个关闭的条目运行replace provider命令,然后运行terraform init来纠正它。我注意到这样做并运行git diff,tfstate已经更新,现在使用0.14.x terraform,而不是我以前的0.12.x

    terraform providers
    
    terraform state replace-provider registry.terraform.io/-/azurerm registry.terraform.io/hashicorp/azurerm 
    

    我也有同样的问题。我跑了:

    terraform providers
    
    这给了我:

    Providers required by configuration:
    registry.terraform.io/hashicorp/google
    
    Providers required by state:
    registry.terraform.io/-/google
    
    所以我跑了:

    terraform state replace-provider registry.terraform.io/-/google registry.terraform.io/hashicorp/google
    

    这就成功了。

    谢谢,这是一个很好的观点,我最初没有仔细阅读文档,没有意识到应用状态是必要的。但是我想这意味着我需要在本地运行它-在我的情况下,这不是一个好的选择…希望有办法解决这个问题。尝试更改Hashicorp/Google(在req提供者中)到hashicorp/terraform提供者google。我相信这是新的源链接。此外,您应该考虑更新到google 3.5(最新版本)如果这个答案已经解决了你的问题,请考虑通过点击复选标记来接受它。这向更广泛的社区表明,你已经找到了解决方案,并给回答者和你自己带来了一些声誉。运行TrRAFFAL提供者,你可以查看哪一个是冲突的。谢谢!
    Providers required by configuration:
    registry.terraform.io/hashicorp/google
    
    Providers required by state:
    registry.terraform.io/-/google
    
    terraform state replace-provider registry.terraform.io/-/google registry.terraform.io/hashicorp/google