vRA Tips and Tricks – Part 2

This article series will focus on specific tips and tricks to aid customisation and flexibility of vRA 8.x.


Ternary Logic

Otherwise known as three-valued logic, this logic system differs from the Boolean True and False that we use more commonly by adding a third value. Simplistically this would present as:

IF SomeValue, THEN value=A ELSE value=B

The vRA blueprint schema supports ternary logic as can be seen in the documentation example “For deploying to VMware Cloud on AWS, set the folder name to the required name of Workload”

folderName: '${input.environment == "VMC" ? "Workload" : ""}'

A generic way to describe this in vRA blueprint expression format would be:

${IfSomething == “true” ? “returnSomething” : “elseReturnSomethingElse” } }

You could even get more complicated with the inclusion of AND and OR statements (expressed as “&&” and “||” in the code). For example:

property: ‘${IfSomething1 == “true” && IfSomething2 == “true” || IfSomething1 == “true” && IfSomething3 == “true”  ? “true” : “false” }’

So, enough of the academic definition – let’s see a practical example!

The objective: Design a single blueprint that can be used for both Dev/Test and Production environments that will assign a different network based on the chosen environment.

Here’s the blueprint code:

name: Ternary Logic
formatVersion: 1
    type: string
    title: Environment
    description: Select a deployment environment
      - title: Dev/Test
        const: DevTest
      - title: Production
        const: Prod
    default: Prod
    type: string
    # Set the values below as 'image name,customisation spec'
      - title: Microsoft Windows Server 2019
        const: 'windows-server-2019,windows-spec-noad'
      - title: CentOS Server 7.9
        const: 'centos-79,linux-spec'
      - title: CentOS Server 8.3
        const: 'centos-83,linux-spec'
    title: Operating System
    description: Select an operating system and version.
# -------------------------RESOURCES----------------------#
    type: Cloud.vSphere.Machine
      image: '${split(input.operatingSystem,",")[0]}'
      customizationSpec: '${split(input.operatingSystem,",")[1]}'
      flavor: small
        - tag: 'cloud:private'
        - network: '${resource["Network"].id}'
          assignment: static
    type: Cloud.NSX.Network
      networkType: existing
        - tag: '${input.environment == "DevTest" ? "Net-T00-DevTest" : "Net-T00-Prod"}'

If the DevTest environment is selected at Input, the network tag will be Net-T00-DevTest, otherwise it will be Net-T00-Prod.

Of course, you could just specify the Network tag values as constants within the Input stage, but you may want to use the environment value for other things as well – for example to drive a custom naming standard. Another example of ternary logic expression will be in my next post in this series which will be about using Property Groups to abstract the environment specification.

2 thoughts on “vRA Tips and Tricks – Part 2”

Leave a Reply

%d bloggers like this: