Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Output issue with resource_configuration #71

Open
supernini opened this issue May 19, 2020 · 9 comments
Open

Output issue with resource_configuration #71

supernini opened this issue May 19, 2020 · 9 comments

Comments

@supernini
Copy link

supernini commented May 19, 2020

vRA 7.5 version
The vRA 7.5 version where is issue is found.
Terraform version
0.12.24
**terraform-provider-vra7 plugin version
1.0.1

Describe the bug
When it try to output my result, i'm not able to acces

To Reproduce
Steps to reproduce the behavior:

  1. Terraform config file
resource "vra7_deployment" "windows" {
  count             = 1
...
  resource_configuration {
    component_name = "server1"
    configuration = {
      hostname = "ServerName"
   ...
   }
  ....
}
output "machine-names" {
  value = ["${vra7_deployment.windows[*].resource_configuration.server1.hostname}"]
}
  1. Terraform command
    terraform apply
  2. Error
    `Error: Unsupported attribute

on main.tf line 125, in output "machine-names":
125: value = ["${vra7_deployment.windows[*].resource_configuration.server1.hostname}"]

This value does not have any attributes.`
(server1 is underlined)

Expected behavior
It should output the hostname

@hobovirtual
Copy link

hobovirtual commented May 19, 2020

Hi @supernini

If you only have one resource_configuration, try the following

output "vm_name" {
  value = ["${vra7_deployment.windows[*].resource_configuration[*].name}"]
}

Think the issue is due to the fact the resource_configuration is an array which needs to be treated differently

@supernini
Copy link
Author

supernini commented May 19, 2020

Thanks @hobovirtual, but i've got the same error

But following your comment i try this :
value = ["${vra7_deployment.windows[*].resource_configuration[*].configuration.hostname}"]

And it's start (now i wait for the result)

@supernini
Copy link
Author

The solution i post works fine. Is it the right one ;-)

@MasakariDOR
Copy link

In a related question, is the only way to access the resource_configuration without the splat to use a for loop? It seems that resource_configuration is a "set" and not a "list" as one would expect. Not sure if this is desired behaviour or not. Even using a for loop, I cannot access the properties under the child "configuration" object.

output "myValue" {
   value = vra7_deployment.windows-web[0].resource_configuration[0].name
}

Error message:

Block type "resource_configuration" is represented by a set of objects, and
set elements do not have addressable keys. To find elements matching specific
criteria, use a "for" expression with an "if" clause.

@MasakariDOR
Copy link

When accessing the properties of the configuration object I get this weirdness:

output "myValue" {
   value = {
       for resource in vra7_deployment.windows-web[0].resource_configuration:
           "myConfig" => resource.configuration.MachineBlueprintName
   }
}

Error:

Error: Missing map element

  on windows-web\output.tf line 10, in output "myValue":
  10:            "myConfig" => resource.configuration.MachineBlueprintName
    |----------------
    | resource.configuration is map of string with 15 elements

This map does not have an element with the key "MachineBlueprintName".

When I examine the keys I can see this is a valid key (and there are 46 of them, not 15!):

output "myValue" {
   value = {
       for resource in vra7_deployment.windows-web[0].resource_configuration:
           "myConfig" => join(" ",keys(resource.configuration))
   }
}

Output:

myValue = {
  "myConfig" = "ChangeLease ChangeOwner Component ConnectViaNativeVmrc ConnectViaRdp ConnectViaVmrc CreateSnapshot DISK_VOLUMES.0.DISK_CAPACITY DISK_VOLUMES.0.DISK_INPUT_ID DISK_VOLUMES.0.DISK_LABEL DISK_VOLUMES.0.DISK_RESERVATION_POLICY Destroy EXTERNAL_REFERENCE_ID Expire GetExpirationReminder IS_COMPONENT_MACHINE InstallTools MachineBlueprintName MachineDailyCost MachineDestructionDate MachineExpirationDate MachineGroupName MachineGuestOperatingSystem MachineInterfaceDisplayName MachineInterfaceType MachineReservationName NETWORK_LIST.0.NETWORK_ADDRESS NETWORK_LIST.0.NETWORK_MAC_ADDRESS NETWORK_LIST.0.NETWORK_NAME NETWORK_LIST.0.NETWORK_PROFILE PowerOff Reboot Reconfigure Reprovision Reset Shutdown Suspend VirtualMachine.Admin.UUID cpu endpointExternalReferenceId ip_address machineId memory name storage type"
}

@ricardf
Copy link

ricardf commented Aug 19, 2020

Is there any way to read the ip_address having multiple resource_configurations ?

@Prativa20
Copy link
Contributor

Prativa20 commented Aug 19, 2020

Hi @ricardf

Are you looking for this?

output "ip" { value = vra7_deployment.machine[*].resource_configuration[*].ip_address }

The result will be something like this:

Outputs:
ip = [
    [
        "10.xxx.xxx.xxx",
        "192.xxx.xxx.xxx",
        "192.xxx.xxx.xxx",
    ],
]

@ricardf
Copy link

ricardf commented Aug 20, 2020

Hi @ricardf

Are you looking for this?

output "ip" { value = vra7_deployment.machine[*].resource_configuration[*].ip_address }

The result will be something like this:

Outputs:
ip = [
    [
        "10.xxx.xxx.xxx",
        "192.xxx.xxx.xxx",
        "192.xxx.xxx.xxx",
    ],
]

I'm trying to get only 1 of those IPS by the component_name

@thiagomarinho
Copy link

So, I managed to get a list like this:

flatten([for rc in vra7_deployment.deployment.resource_configuration : rc.instances[*].ip_address if rc.component_name == "APP"])

"APP" is the resource name defined at vRA catalog item.

Is there any other way than using for and if statements to get properties from a specific resource with multiple resource_configurations?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants