Terraform 模块抛出关于需要字符串的错误
Terraform module throws error about requiring a string
我一直在尝试将我的 Terraform 代码从一个大文件拆分成单独的模块。我一直 运行 遇到 运行 Terraform Plan.
时出现以下错误的问题
Error: Incorrect attribute value type
on modules/nsg/main.tf line 11, in resource "azurerm_network_security_group" "InternalProdNSGPrivate":
11: resource_group_name = "${module.rg.main-rg-id}"
Inappropriate value for attribute "resource_group_name": string required.
我创建了一个 outputs.tf
文件,其中包含以下内容:
output "main-rg-id" {
value = "${azurerm_resource_group.InternalProd}"
}
此模块的 main.tf
具有以下内容:
module "global_variables" {
source = "../global_variables"
}
resource "azurerm_resource_group" "InternalProd" {
name = "Internal"
location = "${module.global_variables.location}"
}
在 NSG 的 main.tf 文件中,我配置了以下内容:
module "rg" {
source = "../rg"
}
module "global_variables" {
source = "../global_variables"
}
resource "azurerm_network_security_group" "InternalProdNSGPrivate" {
name = "Internal-NSG"
location = "${module.global_variables.location}"
resource_group_name = "${module.rg.main-rg-id}"
....
}
不确定这里的配置哪里出了问题。尝试查看多个不同的资源、博客等,但没有成功。
azurerm_resource_group.InternalProd
是代表整个 resource "azurerm_resource_group" "InternalProd"
的对象。
要仅生成该对象的 ID,您可以像这样访问属性 id
:
output "main-rg-id" {
value = azurerm_resource_group.InternalProd.id
}
我一直在尝试将我的 Terraform 代码从一个大文件拆分成单独的模块。我一直 运行 遇到 运行 Terraform Plan.
时出现以下错误的问题Error: Incorrect attribute value type
on modules/nsg/main.tf line 11, in resource "azurerm_network_security_group" "InternalProdNSGPrivate":
11: resource_group_name = "${module.rg.main-rg-id}"
Inappropriate value for attribute "resource_group_name": string required.
我创建了一个 outputs.tf
文件,其中包含以下内容:
output "main-rg-id" {
value = "${azurerm_resource_group.InternalProd}"
}
此模块的 main.tf
具有以下内容:
module "global_variables" {
source = "../global_variables"
}
resource "azurerm_resource_group" "InternalProd" {
name = "Internal"
location = "${module.global_variables.location}"
}
在 NSG 的 main.tf 文件中,我配置了以下内容:
module "rg" {
source = "../rg"
}
module "global_variables" {
source = "../global_variables"
}
resource "azurerm_network_security_group" "InternalProdNSGPrivate" {
name = "Internal-NSG"
location = "${module.global_variables.location}"
resource_group_name = "${module.rg.main-rg-id}"
....
}
不确定这里的配置哪里出了问题。尝试查看多个不同的资源、博客等,但没有成功。
azurerm_resource_group.InternalProd
是代表整个 resource "azurerm_resource_group" "InternalProd"
的对象。
要仅生成该对象的 ID,您可以像这样访问属性 id
:
output "main-rg-id" {
value = azurerm_resource_group.InternalProd.id
}