VMware Cloud Community
RobertPr
Contributor
Contributor

vRA 8.5 - Define Machine Properties by Input Array

Hi,

I'm trying to define in a multi-machine Cloud Template per instance: OS, flavor and some boolean values.

For this case I have a Input array, which is defined as following:

inputs:
  win:
    type: array
    title: Win2022
    minItems: 0
    maxItems: 10
    items:
      type: object
      properties:
        flavor:
          type: string
          title: Flavor
          description: |-
            <b> Select the size of the deployment. </b> <br>
            Micro = 1 CPU - 1 GB RAM, <br>
            Small =  1 CPU - 2 GB RAM, <br>
            Medium = 2 CPU - 4 GB RAM, <br> 
            Large = 2 CPU - 8 GB RAM <br>
          enum:
            - tiny
            - small
            - medium
            - large
        name1:
          type: string
          title: name
        chkOcr:
          type: boolean
          title: OCR allow
          default: false
        os:
          type: string
          title: OS
          default: '2019'
          enum:
            - '2016'
            - '2019'
            - '2022'

In the Cloud.vSphere.Machine resource I have configured the properties with the "count.index":

  Cloud_vSphere_Machine_1:
    type: Cloud.vSphere.Machine
    properties:
      image: 'Win${input.win[count.index].os}-CS'
      flavor: '${input.win[count.index].flavor}'
      name: '${input.win[count.index].name1}'
      count: ${length(input.win)}
      customizationSpec: null
      ocr: '${input.win[count.index].chkOcr}'
      networks:
        - network: '${resource.Cloud_vSphere_Network_1.id}'
          assignment: static

But the count.index isn't working here. When the resources are creating, all count.indexes are 0, when the deployment has finished the count.indexes are correct, but the resources don't change the OS, flavor and other values.

Can anybody help me with this topic. When the count.index is the wrong way, has anybody a solution to assign different properties per instance?

Thank you, 

br, Robert

 

Reply
0 Kudos
4 Replies
emacintosh
Hot Shot
Hot Shot

Was this something you saw somewhere - in documentation, a blog post, etc?  Or something you were just hoping would work?

 

I'm trying to think through how it would work.  I understand what you're trying to do, and I think it would be cool if it can work.  But I'm not sure how there can have a count of different things.  Meaning, the machine is a thing.  It has properties like the OS, Flavor, etc.  And count is just one of those properties.  So it would be like having x number of clones of the machine with all of its other properties.  That's why I don't think this could work.  But I hope I'm wrong.

 

That said, I wonder if there's a way to create multiple individual machines, each with their own properties, each with a count of 1 by referencing the input array.  But I am not sure if that would be valid/legal to do for the cloud template yaml.

Reply
0 Kudos
j_dubs
Enthusiast
Enthusiast

 

 

 

 

Hey RobertPr,

We had something similar, but with disk resources.  For us, instead of an object array, it's a stringified JSON array - but makes no difference really.

Here is our code - and I think what you are missing here is 'allocatePerInstance: true'

 

 

  Cloud_Volume_1:
    type: Cloud.vSphere.Disk
    allocatePerInstance: true
    properties:
      constraints:
        - tag: '${input.Pod}'
        - tag: '${input.Environment}'
        - tag: '${input.Business_Entity}'
      capacityGb: '${from_json(input.diskGrid)[count.index].size}'
      count: '${length(from_json(input.diskGrid))}'
      SCSIController: SCSI_Controller_0
      unitNumber: '${(count.index+1)}'

 

Here is the reference in the documentation for this (resource flags, set outside of the properties block): https://docs.vmware.com/en/VMware-Cloud-Assembly/services/Using-and-Managing/GUID-B76918AE-D18D-4821...

 

RobertPr
Contributor
Contributor

yeah @j_dubs - the "allocatePerInstance" Parameter was the solution! Now it works as expected.

2021-10-15 15_40_53-Clipboard.png

RobertPr_0-1634305823051.png

 

Thank you very much! 🙂

Reply
0 Kudos
j_dubs
Enthusiast
Enthusiast

Awesome, glad it worked out.  We found this after a vRA upgrade that was breaking our workaround to this limitation from back in the day 🙂

Cheers

Reply
0 Kudos