terraform - Terraform 模块抛出关于需要字符串的错误
问题描述
我一直在尝试将我的 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
}
推荐阅读
- python - Dlib 未在 Google Colab 上使用 GPU
- amazon-web-services - 在 Glue 数据目录中为 S3 和未知模式中的数据创建表
- python - TensorFlow中重复训练和预测如何避免OOM错误?
- vba - 使用 VBA 输入后检查是否存在 HTML 元素无法使用 html.getElementById()
- python - 使用python未成功显示成绩
- c - 如何在 macOS 中编译 Rust no_mangle 函数调用 C 函数
- android - 在 Android Kotlin 中无法访问 dialog.getButton()
- laravel - Laravel 缓存是做什么用的?
- sql - 更新 table1 时,如何为表 1 中的每个更改插入到 table2?
- drupal-7 - Drupal 7:订单完成和用户注销时拒绝访问?