craigso
Enthusiast
Enthusiast

vRA8: Apply vSphere tag to VM based on form element

First of I hope this is not a duplicate post. I've searched for an answer before posting but no luck.

I would like to apply a vSphere tag to a VM at provisioning time based on user input (check box) on the request form. If the box is checked, apply a tag. If not checked, no tag. I know I can achieve this via a subscription and older vAPI method commonly used in vRA 7.x.

I'd like to use the vRA8 method if possible, by declaring the tag in the YAML code and allowing vRA to apply the tag to the VM if a boolean (checkbox) is true. Either that or something similar. 

Is this possible? Or is there another approach I should be taking?

 

Thanks for reading.

Tags (2)
0 Kudos
3 Replies
j_dubs
Enthusiast
Enthusiast

If I understand correctly, you want a particular tag applied only if the checkbox is set to true, and otherwise, no tag?

We have done something similar in our environment, but just value of the tag is different based on input - tag is always applied.  Maybe you can use this for inspiration.  There are a lot of blueprint expressions you can use.. below are some samples we use:

 

Cloud_Network:
    type: Cloud.Network
    properties:
      networkType: existing
      constraints:
        - tag: '${input.Cloud}'
        - tag: '${input.Region}'
        - tag: '${input.Environment}'
        - tag: '${input.Pod == "Pod:MS-SQL" || input.Pod == "Pod:Oracle" || input.Pod == "Pod:Oracle RAC" ? "Tier:Database" : input.Tier}'
        - tag: '${input.Business_Entity}'
        - tag: '${input.Tenant}'

 

//user ternary operator to set network assignment "static" if input is vsphere, otherwise use "dynamic"
assignment: '${input.Cloud == "Cloud:vsphere" ? "static" : "dynamic"}'

//construct key:value pairs by string manipulations on inputs.  Input would be something like input.Environment=Environment:PROD
 tags:
        - key: '${split(input.Business_Entity,'':'')[0]}'
          value: '${split(input.Business_Entity,'':'')[1]}'
        - key: '${split(input.Environment,'':'')[0]}'
          value: '${split(input.Environment,'':'')[1]}'
craigso
Enthusiast
Enthusiast

Ah interesting, this may work. My use case is applying a "No backups" tag to opt out, which I was struggling to do conditionally. Simply changing the tag value to "backups" or "No backups" should be sufficient for the external backup logic. It would only look for the "No Backups" tag.

I'll give it a go. Thanks for the reply!

0 Kudos
craigso
Enthusiast
Enthusiast

This worked great. I essentially just created a throw away tag and a the tag I'm interested in. Then use the expression to assign either the backup tag or a throw away. 

Thanks for the assist.

0 Kudos