0
votes

I've been trying to split my terraform code from one large file into separate modules. I keep running into an issue where the following error appears when running 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.

I created an outputs.tf file which has the following:

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

The main.tf for this module has the following:

module "global_variables" {
  source = "../global_variables"
}

resource "azurerm_resource_group" "InternalProd" {
  name     = "Internal"
  location = "${module.global_variables.location}"
}

In the main.tf file for the NSG i have the following configured:

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}"
....
}

Not sure where im going wrong here with the configuration. Tried looking at multiple different resources, blogs, etc. but no luck.

1

1 Answers

1
votes

azurerm_resource_group.InternalProd is an object representing the whole of resource "azurerm_resource_group" "InternalProd".

To produce just the id of that object, you can access attribute id like this:

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