【问题标题】:Terraform - Error: Provider configuration not present (passing multiple Azure providers)Terraform - 错误:提供程序配置不存在(传递多个 Azure 提供程序)
【发布时间】:2021-09-28 10:22:25
【问题描述】:

我正在关注本指南https://github.com/hashicorp/terraform/blob/v0.13/website/docs/configuration/modules.html.md#passing-providers-explicitly

这是一个全新的 Terraform 项目,即没有资源和一个空状态文件! terraform 的版本是 Terraform v0.14.5。

在调用模块中,我的提供程序设置如下

terraform {

  backend "azurerm" {

  }
   required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.68.0"
    }
  }
}


provider "azurerm" {
  alias           = "lz"
  subscription_id = "xxx-xxx-xxx-xxx"

  features {}
}

provider "azurerm" {
  alias           = "prd"
  subscription_id = "xxx-xxx-xxx-xxx"

  features {}
}

我正在调用传递多个这样的提供程序的模块

module "prod" {
  source = "../../../Terraform/modules/LandingZone"

  providers = {
    azurerm.lz = azurerm.lz
    azurerm.prd = azurerm.prd
  }
}

在被调用的模块中,我在 providers.tf 中有这个

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.68.0"
    }
  }
  backend "azurerm" {

  }
}

provider "azurerm" {
   alias           = "lz"
   features{}
}


provider "azurerm" {
  alias           = "prd"
  features{}
}

到目前为止,init 和 plan 工作正常。但是,当我尝试创建这样的资源时

resource "azurerm_resource_group" "this" {
  provider= azurerm.lz
  
  for_each = var.rg_names  
  name     = each.value
  location = "Australia Southeast"
}

我收到此错误消息

Error: Provider configuration not present

To work with module.trn.module.rg.azurerm_resource_group.this its original
provider configuration at
module.trn.module.rg.provider["registry.terraform.io/hashicorp/azurerm"].lz is
required, but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in the state.
Re-add the provider configuration to destroy
module.trn.module.rg.azurerm_resource_group.this, after which you can remove
the provider configuration again.

【问题讨论】:

  • 这里有几个不同的相关问题,但根本原因是您将托管配置中的资源的提供程序配置更改为提供程序无法更新的内容,而它仍然存在于状态。您需要为新的提供者配置重新创建(删除和创建)此资源。

标签: terraform terraform-provider-azure terraform0.12+


【解决方案1】:

从您链接的指南中,

代理配置块是只包含alias 参数的块。

您的模块中的提供程序块不仅仅是alias 参数,因此它们可能没有被设置为代理提供程序配置。尝试从模块内的提供程序块中删除 features{} 部分。

【讨论】:

    【解决方案2】:

    参考this 指南,您应该在 terraform 块内为所需的提供者声明configuration_aliases。你也可以试试这个。

    【讨论】:

    • 是的也试过了,但它是 Terraform 的 v15 功能
    猜你喜欢
    • 2021-08-04
    • 1970-01-01
    • 2021-04-02
    • 2020-02-12
    • 1970-01-01
    • 2023-04-02
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多