【发布时间】:2021-09-28 10:22:25
【问题描述】:
这是一个全新的 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+