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.