How to convert list to string
i have used count to create multiple subnets and i’m attaching these id’s to multiple nsg in module but having issue with string
output "subnet_ids" {
value = "${azurerm_network_interface.network_interface_ids.*.id}"
}
output result :-
subnet_ids = [
[
"/subscriptions/f2saaa4-7asd4-b8d-4352-0494754kj8/resourceGroups/rg-1/providers/Microsoft.Network/networkInterfaces/web-vm-2",
"/subscriptions/f2saaa4-7asd4-b8d-b83422-0494754kj8/resourceGroups/rg-1/providers/Microsoft.Network/networkInterfaces/web-vm-1",
],
]
i’m creating modules by using count.
#Root module main.tf
module "subnet" {
source = "./module/subnet"
resource_group_name = var.resource_group_name
resource_group_location = var.resource_group_location
virtual_network_name_1 = module.virtual_network.virtual_network_name_1
subnet_address_space = var.subnet_address_space
}
module "network_interface_card" {
source = "./module/nic"
resource_group_name = var.resource_group_name
resource_group_location = var.resource_group_location
network_interface_name = var.network_interface_name
subnet_id = module.subnet.nic_subnet_id
}
#Root variable.tf
variable "subnet_names" {
type = list(string)
default = ["production", "staging"]
}
variable "subnet_address_space" {
type = list(string)
default = ["10.0.1.0/24", "10.0.2.0/24"]
}
variable "network_interface_name" {
type = list(string)
default = [ "web-vm-1", "web-vm-2" ]
}
# subnet for nic
variable "nic_subnet_id" {
type = string
default = ""
}
child module output of subnet id’s:-
output "nic_subnet_id" {
value = "${azurerm_subnet.vnet2-prodsubnet.*.id}"
}
The given value is not suitable for child module variable "subnet_ids" defined at module\nsg\variable.tf:48,1-22: string required.