Basic Math in an Aria Automation Cloud Template
I was helping someone with a small challenge in their Aria Automation Cloud template and had to dig to find the solution. They didn’t find any examples through a search, and neither did I – so I thought I would share. The goal was to do basic math (addition) in the YAML of the Cloud Template.
The use case was a cloud template adding multiple disks in a virtual machine. They had a need to control the name of the VMDK differently than was specified in the Project Custom Naming template. They were using an array of disks in the Cloud Template and the index of that array to make the VMDK name unique (The second disk for the vm should be called mytestvm_disk2.vmdk).
As most arrays in computing are, the index was zero-based (the second disk was called mytestvm_disk1.vmdk). While this would provide a unique name for each disk, the preference was to start with 1 to make it easier on the large number of admins who manage workloads in the environment. They tried various ways of formatting the YAML to get the addition correct; but could not find a way that worked as expected.
I cannot share the code that this customer wrote; but have worked up a simple example to illustrate. The use case this code sample represents is not something you would normally do; but will serve to highlight the syntax to allow some basic math in an Aria Automation Cloud Template.
Arithmetic Operation Example
In our example, we want to prompt the consumer of our Cloud Template for a base number and will add 1 to it (BaseNumber +1). This will be appended to the name the user enters for the VM.
As mentioned, they attempted multiple syntax combinations to add the numbers but it kept getting treated like a string
name: ${input.vm-name + input.Base-Number + 1}
The resulting VM was named MyTest01. This was a string concatenation, not an addition.
Aria Automation Cloud Assembly Expression Syntax allows for a number of functions. One of these is to_number(). This allows you to use some basic arithmetic operations and then incorporate that result.
name: ${input.vm-name + to_number(input.base-number + 1)}
Using this code results in a VM named MyTestVM1 – which is the result of adding a number on the form (0) with another integer value (1).