【问题标题】:Terraform module throws error about requiring a stringTerraform 模块抛出关于需要字符串的错误
【发布时间】:2019-11-20 08:08:03
【问题描述】:

我一直在尝试将我的 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}"
....
}

不确定我在哪里配置错误。尝试查看多种不同的资源、博客等,但没有成功。

【问题讨论】:

    标签: terraform terraform-provider-azure terraform-modules


    【解决方案1】:

    azurerm_resource_group.InternalProd 是一个代表整个resource "azurerm_resource_group" "InternalProd" 的对象。

    要仅生成该对象的 id,您可以像这样访问属性 id

    output "main-rg-id" {
      value = azurerm_resource_group.InternalProd.id
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-19
      • 2021-06-23
      • 2021-07-04
      • 2020-09-20
      • 2021-11-27
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多