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

Modify read deployment to read all the properties of the resource #40

Merged
merged 1 commit into from
Apr 8, 2020

Conversation

Prativa20
Copy link
Contributor

Signed-off-by: Prativa Bawri [email protected]

@Prativa20
Copy link
Contributor Author

Prativa20 commented Feb 3, 2020

This PR is addressing the following open issues:

  1. Import a vra7_deployment Need to import existing VMs  #43 Does 'import' work? #29
  2. Provider not returning all the VMs if the cluster size is more than 1 Terraform gets only first VM with _number_of_instances or _cluster > 1 #39
  3. Issues related to fetching ip_addresses Terraform apply returns empty ip address #27 IPAddress return is empty with latest release of vRealize Automation #16
  4. Terraform refresh not working as intended Terraform refresh does not work as intended. #38

What will change?
The "resource_configuration" schema is changed to handle the above issues

Before:

resource_configuration {
    "vSphere1.cpu" = 2
    "vSphere1.memory" = 1024
    "vSphere1._cluster" = 2
    "vSphere.vSphere1CustomProperty" = "machine custom property"
    "vSphere2.cpu" = 1
    "vSphere2.memory" = 2048
}

After:

resource_configuration {
    name = "vSphere1"
    configuration = {
      cpu = 2
      _cluster = 2
      memory = 1024
      vSphere1CustomProperty = "machine custom property"
    }
  }

  resource_configuration {
    name = "vSphere2"
    configuration = {
      cpu = 1
      memory = 2048
    }
  }

The above modification in the TF config file will result in the following tf state file. "resource_configuration" is a list of all the VM data read from vra. This includes ip_address, host_name, etc. It also shows all 3 VMs (including 2 VMs of vSphere1 type as the specified cluster size is 2). This same state will be generated on importing an existing deployment as well.

"resource_configuration": [
              {
                "configuration": {
                  "ChangeLease": "true",
                  "ChangeOwner": "true",
                  "Component": "vSphere1",
                  "ConnectViaNativeVmrc": "true",
                  "ConnectViaRdp": "true",
                  "ConnectViaVmrc": "true",
                  "CreateSnapshot": "true",
                  "DISK_VOLUMES.0.DISK_CAPACITY": "8",
                  "DISK_VOLUMES.0.DISK_INPUT_ID": "DISK_INPUT_ID1",
                  "DISK_VOLUMES.0.DISK_LABEL": "Hard disk 1",
                  "DISK_VOLUMES.1.DISK_CAPACITY": "2",
                  "DISK_VOLUMES.1.DISK_INPUT_ID": "DISK_INPUT_ID2",
                  "Destroy": "true",
                  "EXTERNAL_REFERENCE_ID": "vm-11624",
                  "Expire": "true",
                  "IS_COMPONENT_MACHINE": "false",
                  "InstallTools": "true",
                  "MachineBlueprintName": "Terraform-Simple-BP",
                  "MachineDailyCost": "0",
                  "MachineDestructionDate": "2020-05-18T18:30:00.987Z",
                  "MachineExpirationDate": "2020-02-18T18:30:00.987Z",
                  "MachineGroupName": "Terraform-BG",
                  "MachineGuestOperatingSystem": "",
                  "MachineInterfaceDisplayName": "vSphere (vCenter)",
                  "MachineInterfaceType": "vSphere",
                  "MachineReservationName": "Terraform-reservation",
                  "NETWORK_LIST.0.NETWORK_MAC_ADDRESS": "10:50:59:b6:a3:00",
                  "NETWORK_LIST.0.NETWORK_NAME": "pppp-wdc-ppp-vm-0000",
                  "NETWORK_LIST.0.NETWORK_NETWORK_NAME": "tf_network_profile",
                  "NETWORK_LIST.0.NETWORK_PROFILE": "tf_network_profile",
                  "PowerOff": "true",
                  "Reboot": "true",
                  "Reconfigure": "true",
                  "Relocate": "true",
                  "Reprovision": "true",
                  "Reset": "true",
                  "Shutdown": "true",
                  "Suspend": "true",
                  "Unregister": "true",
                  "VirtualMachine.Admin.UUID": "0745f44c-9999-b78f-91cb-66bdea6170fd",
                  "cpu": "2",
                  "endpointExternalReferenceId": "097cdaa6-9fd7-2277-bd2f-89bbggd04337",
                  "ip_address": "210.109.111.122",
                  "machineId": "a7ngd3b5-932a-43af-8987-4aeae6788a2c",
                  "memory": "1024",
                  "name": "Terraform-B0026",
                  "storage": "10",
                  "type": "Virtual"
                },
                "name": "vSphere1"
              },
              {
                "configuration": {
                  "ChangeLease": "true",
                  "ChangeOwner": "true",
                  "Component": "vSphere1",
                  "ConnectViaNativeVmrc": "true",
                  "ConnectViaRdp": "true",
                  "ConnectViaVmrc": "true",
                  "CreateSnapshot": "true",
                  "DISK_VOLUMES.0.DISK_CAPACITY": "8",
                  "DISK_VOLUMES.0.DISK_INPUT_ID": "DISK_INPUT_ID1",
                  "DISK_VOLUMES.0.DISK_LABEL": "Hard disk 1",
                  "DISK_VOLUMES.1.DISK_CAPACITY": "2",
                  "DISK_VOLUMES.1.DISK_INPUT_ID": "DISK_INPUT_ID2",
                  "Destroy": "true",
                  "EXTERNAL_REFERENCE_ID": "vm-13625",
                  "Expire": "true",
                  "IS_COMPONENT_MACHINE": "false",
                  "InstallTools": "true",
                  "MachineBlueprintName": "Terraform-Simple-BP",
                  "MachineDailyCost": "0",
                  "MachineDestructionDate": "2020-05-18T18:30:03.643Z",
                  "MachineExpirationDate": "2020-02-18T18:30:03.643Z",
                  "MachineGroupName": "Terraform-BG",
                  "MachineGuestOperatingSystem": "",
                  "MachineInterfaceDisplayName": "vSphere (vCenter)",
                  "MachineInterfaceType": "vSphere",
                  "MachineReservationName": "Terraform-reservation",
                  "NETWORK_LIST.0.NETWORK_MAC_ADDRESS": "10:00:56:66:a5:db",
                  "NETWORK_LIST.0.NETWORK_NAME": "ppppp-ppp-sdm-pp-1521",
                  "NETWORK_LIST.0.NETWORK_NETWORK_NAME": "tf_network_profile",
                  "NETWORK_LIST.0.NETWORK_PROFILE": "tf_network_profile",
                  "PowerOff": "true",
                  "Reboot": "true",
                  "Reconfigure": "true",
                  "Relocate": "true",
                  "Reprovision": "true",
                  "Reset": "true",
                  "Shutdown": "true",
                  "Suspend": "true",
                  "Unregister": "true",
                  "VirtualMachine.Admin.UUID": "875a2cd8-1525-abab-e85f-a278689a7535",
                  "cpu": "2",
                  "endpointExternalReferenceId": "827cddd6-abab-1525-e85f-89bbgyu04337",
                  "ip_address": "111.222.111.222",
                  "machineId": "6c44ba4b-ef4a-4c4d-9cff-2e84042be620",
                  "memory": "1024",
                  "name": "Terraform-B0027",
                  "storage": "10",
                  "type": "Virtual"
                },
                "name": "vSphere1"
              },
              {
                "configuration": {
                  "ChangeLease": "true",
                  "ChangeOwner": "true",
                  "Component": "vSphere2",
                  "ConnectViaNativeVmrc": "true",
                  "ConnectViaRdp": "true",
                  "ConnectViaVmrc": "true",
                  "CreateSnapshot": "true",
                  "DISK_VOLUMES.0.DISK_CAPACITY": "8",
                  "DISK_VOLUMES.0.DISK_INPUT_ID": "DISK_INPUT_ID1",
                  "DISK_VOLUMES.0.DISK_LABEL": "Hard disk 1",
                  "DISK_VOLUMES.1.DISK_CAPACITY": "7",
                  "DISK_VOLUMES.1.DISK_INPUT_ID": "DISK_INPUT_ID2",
                  "Destroy": "true",
                  "EXTERNAL_REFERENCE_ID": "vm-13623",
                  "Expire": "true",
                  "IS_COMPONENT_MACHINE": "false",
                  "InstallTools": "true",
                  "MachineBlueprintName": "Terraform-Simple-BP",
                  "MachineDailyCost": "0",
                  "MachineDestructionDate": "2020-05-18T18:29:43.793Z",
                  "MachineExpirationDate": "2020-02-18T18:29:43.793Z",
                  "MachineGroupName": "Terraform-BG",
                  "MachineGuestOperatingSystem": "",
                  "MachineInterfaceDisplayName": "vSphere (vCenter)",
                  "MachineInterfaceType": "vSphere",
                  "MachineReservationName": "Terraform-reservation",
                  "NETWORK_LIST.0.NETWORK_MAC_ADDRESS": "90:50:76:56:aa:2a",
                  "NETWORK_LIST.0.NETWORK_NAME": "ppppp-wdc-ppp-vm-1521",
                  "PowerOff": "true",
                  "Reboot": "true",
                  "Reconfigure": "true",
                  "Relocate": "true",
                  "Reprovision": "true",
                  "Reset": "true",
                  "Shutdown": "true",
                  "Suspend": "true",
                  "Unregister": "true",
                  "VirtualMachine.Admin.UUID": "986ecb4-530f-4de5-530f-87ac53a0c1cc",
                  "cpu": "1",
                  "endpointExternalReferenceId": "827cddd6-530f-530f-bd2f-8987fad04337",
                  "ip_address": "100.200.100.200",
                  "machineId": "f4acefb5-530f-47f0-bd2f-1289888ff49e",
                  "memory": "2048",
                  "name": "Terraform-B0025",
                  "storage": "15",
                  "type": "Virtual"
                },
                "name": "vSphere2"
              }
            ]

An example to output ip_addresses:

output "ip_addresses" {
  value = vra7_deployment.deployment1[*].resource_configuration[*].configuration.ip_address
}

This results in the following:

"outputs": {
    "ip_addresses": {
      "value": [
        [
          "210.109.111.122",
          "111.222.111.222",
          "100.200.100.200"
        ]
      ]
    }
  }

Taking the discussion in #41 further.
I would appreciate feedback on this before merging. I have attached the binaries for different platforms with the new changes and an example TF config below.
@markpeek @cars @mcascone @GMZwinge @hobovirtual @diogoferreirasky

Binaries:

Linux
linux.zip

Mac/Darwin
darwin.zip

Windows
windows.zip

Example:

provider "vra7" {
  username = "${var.username}"
  password = "${var.password}"
  tenant = "${var.tenant}"
  host = "${var.host}"
  insecure = true
}

resource "vra7_deployment" "deployment1" {
  count = 1
  catalog_item_name = "Terraform-Simple-BP"
  description = "Prativa's deployment vra 7.5"
  reasons = "Testing the vRA 7 Terraform plugin"

  deployment_configuration = {
    "_leaseDays" = "15"
    "BPCustomProperty" = "custom deployment property"
  }

  resource_configuration {
    name = "vSphere1"
    configuration = {
      cpu = 2
      _cluster = 2
      memory = 1024
      vSphere1CustomProperty = "machine custom property"
    }
  }

  resource_configuration {
    name = "vSphere2"
    configuration = {
      cpu = 2
      memory = 2048
    }
  }

  wait_timeout = 15
  businessgroup_name = "Terraform-BG"
}

@GMZwinge
Copy link

@Prativa20 It looks almost perfect. There is just one small problem that I don't know how to resolve. I usually run the provisioners in modules that I can reuse from different providers. The modules are usually different for each of the resource_configuration. This means that I need to call the module for each resource_configuration only with the IP addresses for that configuration. I couldn't figure out how to do that. I tried something like this, but it's not accepted: vra7_deployment.deployment1[*].resource_configuration[vSphere1].configuration.ip_address. Any idea?

In addition, the module will also need the count of the VM for the resource_configuration. How can it be obtained?

Thanks in advance.

@Prativa20
Copy link
Contributor Author

Hi @GMZwinge I haven't tried it yet but I believe we can make use of terraform conditional operators https://www.hashicorp.com/blog/terraform-0-12-conditional-operator-improvements/

Something like,
if (vra7_deployment.deployment1[].resource_configuration. name == "vSphere1") {
//output the ip_address from
vra7_deployment.deployment1[
].resource_configuration.configuration.ip_address
}

If we can translate this logic to use these conditional operators.
I will update if I can figure it out.

Thanks,
Prativa

@moogster
Copy link

Hi @GMZwinge I haven't tried it yet but I believe we can make use of terraform conditional operators https://www.hashicorp.com/blog/terraform-0-12-conditional-operator-improvements/

Something like,
if (vra7_deployment.deployment1[].resource_configuration. name == "vSphere1") { //output the ip_address from vra7_deployment.deployment1[].resource_configuration.configuration.ip_address
}

If we can translate this logic to use these conditional operators.
I will update if I can figure it out.

Thanks,
Prativa

Hi,
I'm trying to implement the above suggestion to iterate a remote-exec script across multiple VM's. I am getting the following error:
Block type "resource_configuration" is represented by a set of objects, etc. Tor find elements matching specific criteria, use a "for" expression with an "if" clause.
My remote-exec worked before the upgrade to the beta provider.

Any ideas?

Thanks

@t-settle
Copy link

How is this PR coming? My organization is very interested in Terraform being able to return all the VRA values of all VMs as we are integrating with Hashicorp Sentinel for policy validation.

@dsiegmann
Copy link

Hi, we are also waiting for this issue to be resolved as without getting all properties like IP the provider and terraform as well is almost unusable for our scenario.

@alteriks
Copy link

alteriks commented Mar 3, 2020

Hi @Prativa20 thanks for maintaining vra7 provider. I've managed to deploy infrastructure using vra7 provider from this PR on VMware vRealize Automation 7.6.
Finally I can get a list of IPs in output, so it's a big advantage. Additionally, I can use this provider alongside with remote-exec and fully provision new VMs with ansible.
Unfortunately, now vra7 is not idempotent. My main.tf

Uncommenting lifecycle block in vra7_deployment resource, makes code idempotent at the expense of making further customization.

  # lifecycle {
  #   ignore_changes = all
  # }

@moogster
Copy link

moogster commented Mar 6, 2020

Hi,
I can deploy VM's using the vRA provider and configure 'output' to display a list of ip addresses. How do I pass on the ip_addresses to a remote-exec? The method I used with a previous version of the provider no longer works and states that a "for" expression with an "if" clause must be used. I cannot find any useful information on how to get this to work.

Thanks

@mcascone
Copy link

mcascone commented Mar 9, 2020

@moogster post your code so we can take a look.

@moogster
Copy link

moogster commented Mar 10, 2020

The following used to work in a remote-exec with terraform v0.12.5 and provider.vra7 v0.5.0
host=self.resource_configuration["CentOS7.name"]

If I use that with terraform v0.12.21 and a beta vra provider, I get the following error:

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.

Thanks

@Prativa20 Prativa20 force-pushed the bawrip-read-deployment branch 4 times, most recently from f30550d to d973230 Compare March 24, 2020 18:59
@ghost ghost added size/XXL documentation and removed size/XL labels Apr 1, 2020
@Prativa20 Prativa20 force-pushed the bawrip-read-deployment branch 3 times, most recently from 17d524c to b1dd8da Compare April 5, 2020 18:56
@Prativa20 Prativa20 added the feature request New feature request label Apr 6, 2020
@Prativa20 Prativa20 requested a review from markpeek April 6, 2020 07:50
@Prativa20 Prativa20 force-pushed the bawrip-read-deployment branch 3 times, most recently from a955652 to f02e408 Compare April 7, 2020 00:46
Copy link
Contributor

@markpeek markpeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks real good. Thank you for taking on this big update! There are some doc changes necessary but approving in advance of those changes.

README.md Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@markpeek markpeek merged commit 0a2693f into master Apr 8, 2020
@t-settle
Copy link

t-settle commented Apr 8, 2020

I pulled down v1.0.0 and tested. It is working wonderfully. Love the new features like day2 scaling, ability to call multiple components in same deployment, and returning all resource values to tfstate.

@mcascone
Copy link

mcascone commented Apr 8, 2020

Hi, I'm just getting a chance to test this now, I am getting an authentication error:

Error: Error applying plan:

1 error occurred:
        * vra7_deployment.TF-Deploy-Windows: 1 error occurred:
        * vra7_deployment.TF-Deploy-Windows: vRealize API: [{Code:50505 Message:System exception. SystemMessage:Access is denied} {Code:403 Message: SystemMessage:}]

My config looks like this. I am still on TF v0.11 as i was getting the parallel-provisioning issue with 0.12. Is it possible that this fixes that? (I can look up the issue #'s if necessary)

provider "vra7" {
  version = "~> 1"
  username = "${var.VRA_USER}"
  password = "${var.VRA_PASS}"
  tenant = "${var.vra_tenant}"
  host = "${var.vra_url}"
}

resource "vra7_deployment" "TF-Deploy-Windows" {
  count             = "${var.server_count}"
  description       = "Terraform Deploy ${count.index + 1}"
  catalog_item_name = "${var.vra_windows_cat_item_name}"
  businessgroup_name = "${var.business_group}"
  wait_timeout      = "2000"

  # lifecycle {
  #   create_before_destroy = true
  # }

  # deployment_configuration = {
  #   _leaseDays  = "${var.lease_days}"
  # }

  resource_configuration {
    component_name = "vSphere__vCenter__Machine_1"
    configuration = {
        cpu          = 1
        _cluster     = 1
        description = "Terraform Windows Machine ${count.index + 1}"
    }
  }

@Prativa20
Copy link
Contributor Author

I pulled down v1.0.0 and tested. It is working wonderfully. Love the new features like day2 scaling, ability to call multiple components in same deployment, and returning all resource values to tfstate.

@t-settle Thanks for the feedback :) Please open new issues if you find any.

@Prativa20
Copy link
Contributor Author

Hi, I'm just getting a chance to test this now, I am getting an authentication error:

Error: Error applying plan:

1 error occurred:
        * vra7_deployment.TF-Deploy-Windows: 1 error occurred:
        * vra7_deployment.TF-Deploy-Windows: vRealize API: [{Code:50505 Message:System exception. SystemMessage:Access is denied} {Code:403 Message: SystemMessage:}]

My config looks like this. I am still on TF v0.11 as i was getting the parallel-provisioning issue with 0.12. Is it possible that this fixes that? (I can look up the issue #'s if necessary)

provider "vra7" {
  version = "~> 1"
  username = "${var.VRA_USER}"
  password = "${var.VRA_PASS}"
  tenant = "${var.vra_tenant}"
  host = "${var.vra_url}"
}

resource "vra7_deployment" "TF-Deploy-Windows" {
  count             = "${var.server_count}"
  description       = "Terraform Deploy ${count.index + 1}"
  catalog_item_name = "${var.vra_windows_cat_item_name}"
  businessgroup_name = "${var.business_group}"
  wait_timeout      = "2000"

  # lifecycle {
  #   create_before_destroy = true
  # }

  # deployment_configuration = {
  #   _leaseDays  = "${var.lease_days}"
  # }

  resource_configuration {
    component_name = "vSphere__vCenter__Machine_1"
    configuration = {
        cpu          = 1
        _cluster     = 1
        description = "Terraform Windows Machine ${count.index + 1}"
    }
  }

@mcascone Regarding the authentication error, if the creds are correct, it should not throw this error. Can you please attach the vra-terraform.log file. Also, we do not validate SSL certificates, so add insecure=true if any certificate errors.

The config file looks fine except one change that you can do, although it will not make any difference at this point unless you try scaling day 2 operations. Remove _cluster from configuration block and add a cluster property as follows.

resource_configuration {
component_name = "vSphere__vCenter__Machine_1"
cluster = 1
configuration = {
cpu = 1
description = "Terraform Windows Machine ${count.index + 1}"
}
}

For the parallel-provisioning issue, it would be great if you can provide the issue that you are talking about.

@mcascone
Copy link

mcascone commented Apr 9, 2020

Terraform log is at https://gist.github.com/mcascone/ce21c1f654992f90a8f37137ed730712

Where does the insecure go? I put it in the provider block, but it didn't change anything; putting it in the resource block caused a syntax failure.

The parallel provision issue is here, and it is pretty much blocking everything for me: hashicorp/terraform#22722

@Prativa20
Copy link
Contributor Author

@mcascone From the logs, it seems that fetching the business groups for this tenant is throwing this error.

insecure will go in the provider block.

I am not sure about the parallel provisioning issue. I will look into it and update.

@mcascone
Copy link

@Prativa20, i updated the gist with the full debug log of the issue i'm seeing: https://gist.github.com/mcascone/ce21c1f654992f90a8f37137ed730712 (actual cloud URL redacted in the logs)

Any insight on the parallel issue?

@Prativa20
Copy link
Contributor Author

@Prativa20, i updated the gist with the full debug log of the issue i'm seeing: https://gist.github.com/mcascone/ce21c1f654992f90a8f37137ed730712 (actual cloud URL redacted in the logs)

Any insight on the parallel issue?

@mcascone The request to get subtenants/business groups for the tenant 'Engineering' is throwing 403. Please check your vRA administration setup.
https://my-vra-host/identity/api/tenants/Engineering/subtenants
The response is: 403

To unblock, you can try the following:
With the another new provider version v1.0.1 that should be published anytime soon, you can get rid of business group name or id in your config file and it will assume the default business group in the catalog item request template.

Let me know if that works for you.

@mcascone
Copy link

mcascone commented Apr 21, 2020

Hi, thanks so much for your quick action on all this. Removing the business group name does make the request go though!

Now, i've progressed to the next error... I don't know if this is a driver issue or an issue with my org's vRA instance:

Error: Error applying plan:

1 error occurred:
        * vra7_deployment.TF-Deploy-Windows: 1 error occurred:
        * vra7_deployment.TF-Deploy-Windows: Request failed
 The following component requests failed:
vSphere__vCenter__Machine_1. Request failed: Machine MTPCTSDEV00281: CloneVM :  [ApplyStorageDrsRecommendation_Task] - The resource '12668' is in use. and MTPCTSDEV00281: sendEBSMessage23(workflow=e4511745-98a7-4897-8c96-4645c1e8c4f3) Error in state VMPSMasterWorkflow32.Disposing phase PRE event (queue = fb939ded-fb4f-465a-a3e7-797b9c050404):
Extensibility consumer error(20999) - TypeError: Cannot read property "runtime" from null.

I am still on TF 0.11 due to the parallel issue mentioned above.

Terraform v0.11.14
+ provider.vra7 v1.0.1

Update: it was indeed an issue with our vCenter config. Our admin tweaked it - i don't know what the change was - and now it works!

@mcascone
Copy link

mcascone commented Apr 21, 2020

With a configuration as follows, how do i get the IP and Name? I can't come up with a valid output line. Will it not work with TF v0.11?

resource "vra7_deployment" "TF-Deploy-Windows" {
  count              = 2
  description        = "Terraform Deploy ${count.index + 1}"
  catalog_item_name  = "${var.vra_windows_cat_item_name}"
  wait_timeout       = "2000"
  lease_days         = 7

  resource_configuration {
    component_name = "vSphere__vCenter__Machine_1"
    cluster        = 1

    configuration = {
      cpu         = 2
      memory      = 4096
      description = "Terraform Windows Machine ${count.index + 1}"
    }
  }
}

# note: i can not come up with a version of this syntax that passes validation
output "Windows Machine Names" {
  value = ["${vra7_deployment.TF-Deploy-Windows.*.resource_configuration.*.name}"]
}

State file:

vra7_deployment.TF-Deploy-Windows[1]
      id:                                                          <computed>
      businessgroup_id:                                            <computed>
      businessgroup_name:                                          <computed>
      catalog_item_id:                                             <computed>
      catalog_item_name:                                           "MTP_Engineering_DEV_v01"
      date_created:                                                <computed>
      deployment_destroy:                                          "true"
      deployment_id:                                               <computed>
      description:                                                 "Terraform Deploy 2"
      last_updated:                                                <computed>
      lease_days:                                                  "7"
      lease_end:                                                   <computed>
      lease_start:                                                 <computed>
      name:                                                        <computed>
      owners.#:                                                    <computed>
      reasons:                                                     <computed>
      request_status:                                              <computed>
      resource_configuration.#:                                    "1"
      resource_configuration.1006188677.cluster:                   "1"
      resource_configuration.1006188677.component_name:            "vSphere__vCenter__Machine_1"
      resource_configuration.1006188677.configuration.%:           "3"
      resource_configuration.1006188677.configuration.cpu:         "2"
      resource_configuration.1006188677.configuration.description: "Terraform Windows Machine 2"
      resource_configuration.1006188677.configuration.memory:      "4096"
      resource_configuration.1006188677.date_created:              <computed>
      resource_configuration.1006188677.description:               <computed>
      resource_configuration.1006188677.ip_address:                <computed>
      resource_configuration.1006188677.last_updated:              <computed>
      resource_configuration.1006188677.name:                      <computed>
      resource_configuration.1006188677.parent_resource_id:        <computed>
      resource_configuration.1006188677.request_id:                <computed>
      resource_configuration.1006188677.request_state:             <computed>
      resource_configuration.1006188677.resource_id:               <computed>
      resource_configuration.1006188677.resource_type:             <computed>
      resource_configuration.1006188677.status:                    <computed>
      tenant_id:                                                   <computed>
      wait_timeout:                                                "2000"

@t-settle
Copy link

t-settle commented Apr 21, 2020

Try putting your splat in brackets:

vra7_deployment.TF-Deploy-Windows[*].resource_configuration[*].name

@mcascone
Copy link

mcascone commented Apr 22, 2020

Thanks @t-settle, i did try that without success, but i believe that is 0.12 syntax, and I'm on 0.11. There is a separate issue in 0.12 that blocks me from upgrading - although i haven't tried in a while, so maybe i'll update the syntax to 0.12 and try it all again.

@mcascone
Copy link

mcascone commented May 1, 2020

so, i haven't updated to v0.12 syntax yet, but i have made a bit of progress and hit another wall.

With this output configuration, i get the following:

outputs.tf
output "Windows Machine Names" {
value = ["${vra7_deployment.TF-Deploy-Windows.*.resource_configuration}"]
}

result:
Windows Machine Names = [
    [
        map[cluster:1 component_name:vSphere__vCenter__Machine_1 configuration:map[ChangeLease:1 ChangeOwner:1 Component:vSphere__vCenter__Machine_1 ConnectViaNativeVmrc:1 ConnectViaRdp:1 ConnectViaVmrc:1 CreateSnapshot:1 DISK_VOLUMES:map[0:map[DISK_CAPACITY:60 DISK_INPUT_ID:DISK_INPUT_ID1 DISK_LABEL:Hard disk 1]] Destroy:1 EXTERNAL_REFERENCE_ID:vm-719135 Expire:1 IS_COMPONENT_MACHINE:0 InstallTools:1 MachineBlueprintName:MTP_Engineering_DEV_v01 MachineDailyCost:0 MachineDestructionDate:2020-05-08T13:42:15.000Z MachineExpirationDate:2020-05-08T13:42:15.000Z MachineGroupName:Engineering_DEV_ALL MachineGuestOperatingSystem:Microsoft Windows Server 2016 (64-bit) MachineInterfaceDisplayName:vSphere (vCenter) MachineInterfaceType:vSphere MachineReservationName:Engineering_MTP_DEV_A NETWORK_LIST:map[0:map[NETWORK_ADDRESS:<redacted> NETWORK_MAC_ADDRESS:<redacted> NETWORK_NAME:dvPG227]] PowerOff:1 Reboot:1 Reconfigure:1 Relocate:1 Reprovision:1 Reset:1 Shutdown:1 Suspend:1 Unregister:1 VirtualMachine:map[Admin:map[UUID:50219703-5130-2ea1-e130-e642c4515134]] cpu:2 endpointExternalReferenceId:46425f73-27de-427f-ae81-41e7ad39a5b7 ip_address:<redacted> machineId:503b0e14-4434-4b4d-8238-b83e72c1a78b memory:4096 name:<redacted>storage:60 type:Virtual] date_created:2020-04-30T20:30:50.473Z description: ip_address:<redacted> last_updated:2020-05-01T18:42:52.436Z name:<redacted>parent_resource_id:afbde425-e82e-4833-bba5-bad792afd015 request_id:6349d33b-cf81-441f-9ef9-61f606224155 request_state:SUCCESSFUL resource_id:078f11fa-35d6-4a6e-8546-2e082f527f7b resource_type:Infrastructure.Virtual status:On]
    ],
    <repeats for 2nd machine>
]

The terraform.tfstate file looks like this:

> tfs
vra7_deployment.TF-Deploy-Windows.0:
  id = 6349d33b-cf81-441f-9ef9-61f606224155
  businessgroup_id = 900ccac0-013f-4a28-a359-e6f2bb4bcc17
  catalog_item_id = c7bea79f-f8ba-4a1d-94f8-b7202b625af0
  catalog_item_name = MTP_Engineering_DEV_v01
  date_created = 2020-04-30T20:18:47.646Z
  deployment_destroy = true
  deployment_id = afbde425-e82e-4833-bba5-bad792afd015
  description = Terraform Deploy 1
  last_updated = 2020-05-01T18:46:25.113Z
  lease_days = 6
  lease_end = 2020-05-08T13:42:15.500Z
  lease_start = 2020-04-30T20:18:53.152Z
  name = MTP_Engineering_DEV_v01-32276555
  owners.# = 1
  owners.0 = Maximilian Cascone
  request_status = SUCCESSFUL
  resource_configuration.# = 1
  resource_configuration.118971778.cluster = 1
  resource_configuration.118971778.component_name = vSphere__vCenter__Machine_1
  resource_configuration.118971778.configuration.% = 45
  resource_configuration.118971778.configuration.ChangeLease = true
  resource_configuration.118971778.configuration.ChangeOwner = true
  resource_configuration.118971778.configuration.Component = vSphere__vCenter__Machine_1
  resource_configuration.118971778.configuration.ConnectViaNativeVmrc = true
  resource_configuration.118971778.configuration.ConnectViaRdp = true
  resource_configuration.118971778.configuration.ConnectViaVmrc = true
  resource_configuration.118971778.configuration.CreateSnapshot = true
  resource_configuration.118971778.configuration.DISK_VOLUMES.0.DISK_CAPACITY = 60
  resource_configuration.118971778.configuration.DISK_VOLUMES.0.DISK_INPUT_ID = DISK_INPUT_ID1
  resource_configuration.118971778.configuration.DISK_VOLUMES.0.DISK_LABEL = Hard disk 1
  resource_configuration.118971778.configuration.Destroy = true
  resource_configuration.118971778.configuration.EXTERNAL_REFERENCE_ID = vm-719135
  resource_configuration.118971778.configuration.Expire = true
  resource_configuration.118971778.configuration.IS_COMPONENT_MACHINE = false
  resource_configuration.118971778.configuration.InstallTools = true
  resource_configuration.118971778.configuration.MachineBlueprintName = MTP_Engineering_DEV_v01
  resource_configuration.118971778.configuration.MachineDailyCost = 0
  resource_configuration.118971778.configuration.MachineDestructionDate = 2020-05-08T13:42:15.000Z
  resource_configuration.118971778.configuration.MachineExpirationDate = 2020-05-08T13:42:15.000Z
  resource_configuration.118971778.configuration.MachineGroupName = Engineering_DEV_ALL
  resource_configuration.118971778.configuration.MachineGuestOperatingSystem = Microsoft Windows Server 2016 (64-bit)
  resource_configuration.118971778.configuration.MachineInterfaceDisplayName = vSphere (vCenter)
  resource_configuration.118971778.configuration.MachineInterfaceType = vSphere
  resource_configuration.118971778.configuration.MachineReservationName = Engineering_MTP_DEV_A
  resource_configuration.118971778.configuration.NETWORK_LIST.0.NETWORK_ADDRESS = <redacted but here it is>
  resource_configuration.118971778.configuration.NETWORK_LIST.0.NETWORK_MAC_ADDRESS = <redacted>
  resource_configuration.118971778.configuration.NETWORK_LIST.0.NETWORK_NAME = dvPG227
  resource_configuration.118971778.configuration.PowerOff = true
  resource_configuration.118971778.configuration.Reboot = true
  resource_configuration.118971778.configuration.Reconfigure = true
  resource_configuration.118971778.configuration.Relocate = true
  resource_configuration.118971778.configuration.Reprovision = true
  resource_configuration.118971778.configuration.Reset = true
  resource_configuration.118971778.configuration.Shutdown = true
  resource_configuration.118971778.configuration.Suspend = true
  resource_configuration.118971778.configuration.Unregister = true
  resource_configuration.118971778.configuration.VirtualMachine.Admin.UUID = 50219703-5130-2ea1-e130-e642c4515134
  resource_configuration.118971778.configuration.cpu = 2
  resource_configuration.118971778.configuration.endpointExternalReferenceId = 46425f73-27de-427f-ae81-41e7ad39a5b7
  resource_configuration.118971778.configuration.ip_address = <here's another listing of the same ip address>
  resource_configuration.118971778.configuration.machineId = 503b0e14-4434-4b4d-8238-b83e72c1a78b
  resource_configuration.118971778.configuration.memory = 4096
  resource_configuration.118971778.configuration.name = MTPCTSDEV00299
  resource_configuration.118971778.configuration.storage = 60
  resource_configuration.118971778.configuration.type = Virtual
  resource_configuration.118971778.date_created = 2020-04-30T20:30:50.473Z
  resource_configuration.118971778.description =
  resource_configuration.118971778.ip_address = <and yet another ip address listing>
  resource_configuration.118971778.last_updated = 2020-05-01T18:42:52.436Z
  resource_configuration.118971778.name = MTPCTSDEV00299
  resource_configuration.118971778.parent_resource_id = afbde425-e82e-4833-bba5-bad792afd015
  resource_configuration.118971778.request_id = 6349d33b-cf81-441f-9ef9-61f606224155
  resource_configuration.118971778.request_state = SUCCESSFUL
  resource_configuration.118971778.resource_id = 078f11fa-35d6-4a6e-8546-2e082f527f7b
  resource_configuration.118971778.resource_type = Infrastructure.Virtual
  resource_configuration.118971778.status = On
  tenant_id = my-tenant-id
  wait_timeout = 2000

However I can not create the syntax to pull out just the name or IP. Or even the cluster, at the very top of the map. Any further additions to the output line either fail syntax or give no output.

What am I doing wrong?

Whenever i try to put the * in brackets, i get expected expression but found "*"

@mcascone
Copy link

mcascone commented May 1, 2020

Alright, i got it. I upgraded to v0.12, and this simple statement does it:

output "Windows-Machine-Names" {
  value = vra7_deployment.TF-Deploy-Windows[*].resource_configuration[*].name
}

@mcascone
Copy link

mcascone commented May 4, 2020

Another wall: in the chef provisioner in my vra7_deployment resource, how do I get the name/ip of the self object?

This: host = self.resource_configuration[*].name
gives this error: Error: Incorrect attribute value type: Inappropriate value for attribute "host": string required.

I'll try the provisioning in a null_resource object for now, which I've had luck with before.

@hobovirtual
Copy link

hobovirtual commented May 4, 2020

Hi @mcascone

If you're using the latest plugin, please take a look at issue #67 for potential resolution. struggled to get this as well at first.

Thanks!

@hobovirtual
Copy link

Sorry mixed the reference see issue #65

@frodenas frodenas deleted the bawrip-read-deployment branch September 7, 2021 16:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants