The given value is not suitable for child module variable "nic_id" defined at module\nsg\variable.tf:14,1-18: string required

Hi,

i’m new to child modules and i want to create multiple resource with child module using loop but getting error while creating resources. Please help me to fix this issue.

resource “azurerm_resource_group” “rg” {
name = var.resource_group_name
location = var.resource_group_location
}

module “vnet” {
source = “./module/vnet”
resource_group_name = var.resource_group_name
resource_group_location = var.resource_group_location
vnet_name = var.vnet_name
address_space = var.address_space

}

module “subnet” {
source = “./module/subnet”
subent_name = var.subent_name
resource_group_name = var.resource_group_name
vnet_name_outout = module.vnet.vnet_name_outout # output
address_prefixes = var.address_prefixes
}

module “nic” {
source = “./module/nic”
resource_group_name = var.resource_group_name
resource_group_location = var.resource_group_location
nic_names_list = toset(var.nic_names_list)
prodsubnet_id = module.subnet.prodsubnet_id # output
}

module “nsg” {
source = “./module/nsg”
resource_group_name = var.resource_group_name
resource_group_location = var.resource_group_location
nsg_names_list = toset(var.nsg_names_list)
nic_id = module.nic.nic_id # output “nic_id”
}

output “nic_id” {
value = [for s in azurerm_network_interface.web_windows_vm_nic : s.id]
}

Error: Invalid value for module argument

│ on main.tf line 28, in module “nsg”:
│ 28: nic_id = module.nic.nic_id

│ The given value is not suitable for child module variable “nic_id” defined at module\nsg\variable.tf:14,1-18: string required.

resource “azurerm_network_interface_security_group_association” “web_vmnic_nsg_associate” {
for_each = azurerm_network_security_group.prod_subnet_nsg
network_interface_id = var.nic_id
network_security_group_id = each.value.id
}