0
votes

I have a module which is fetching managed disks from a resource group, then i am calling this module from another module where the names of all the managed disk will be displayed.

When i run plan command , i am getting an error "name must be a single value, not a list". How do i display values from a list ??

Module 1 - Fetching Values

data "azurerm_managed_disk" "disk" {
resource_group_name = "mfa-rg"
name = ["*"]
}

output "disks" {  
value = ["${data.azurerm_managed_disk.disk.name}"]

}

Module 2 - calling module 1 to display values

 module "rgmod"{
 source = "./RG"
 }

output "rgdetails"{
value = "${module.rgmod.disks}"
  }
1
Does the error go away if you wrap the rgdetails output in square brackets like you have for the disks output?ydaetskcoR
No it doesnt..i tried that toouser2549572

1 Answers

0
votes

In your issue, when you create the list include all the Azure managed disks, then you can display all the disk name from the list like this:

output "disks" {  
  value = "${data.azurerm_managed_disk.disk.*.name}"
}

Let's take a look at the example of the list of multiple interfaces. When you create multiple interfaces like this:

resource "azurerm_network_interface" "test" {
  count               = 5
  name                = "acceptanceTestNetworkInterface1"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"

  ip_configuration {
    name                          = "testconfiguration1"
    subnet_id                     = "${azurerm_subnet.test.id}"
    private_ip_address_allocation = "Dynamic"
  }

  tags {
    environment = "staging"
  }
}

Then you can display all the interfaces name like this:

    output "disks" {  
      value = "${azurerm_network_interface.test.*.id}"
    }

So, you should make sure the list is a real list. Then just output like above.