I wanted to give my users the capability to create a snapshot but limit them to only 1 snapshot and have a predefined description from the snapshot so i can know that it was taken from vRA.

For the purpose of this i will be using a customer workflow in Orchestrator and Resource Actions and in Cloud Assembly.

Since Orchestrator comes with a number of pre defined workflows in always like to jump start by find something thats similar with what im trying to do. For the purpose of this we will be using the Create Snapshot Workflow.

To get started we can go to Orchestrator -> Workflows -> search for Create a snapshot. Once found we can click on Actions -> Duplicate

The image shows a vRA 8.2 workflow interface with a “Create a snapshot” workflow, displaying options to Schedule, Duplicate, or Tag.

We can see that a Copy has been created. We will modify this so it can fit the custom specifications required.

Click on Open on the Copy:

Copy of Create a snapshot in vCenter for virtual machine management.

Change the name to something more meaningful like VM Snapshot

Enter “VM Snapshot” in the Workflow name field.

Click on Variables, select all the variables and click Delete

In the Variables tab of a VM Snapshot, select all variables and click Delete.

Click on New, give it a title like errMachineHasSnapshot and a value thatw ill displayed if a VM has an existing snapshot like The virtual machine already has a snaphost. Please delete this snapshot before trying this action again. Click Create

Creating a variable for snapshot management in vRA 8.2.

Click on the Schema tab and delete the existing items by clicking on the red x on the top right corner

UI shows workflow diagram with “createSnapshot” and “vim3WaitTaskEnd” nodes.

Drag and drop from the left a Decision, throw exception and a workflow element in to the canvas

Drag and drop Decision, throw exception, and workflow elements into canvas.

I named the first step VM Has Snapshot?. Under inputs i added vm. It would look like the screenshot below

In vRA 8.2, a decision step named “VM Has Snapshot?” checks if a VM has a snapshot, using a custom script.

Under the javascript we will be using this code

    var snapshots = System.getModule("com.vmware.library.vc.vm.snapshot").getAllSnapshotsOfVM(vm) ;
    if (snapshots == null || snapshots.length == 0) {
      // No snapshots found; proceed with creating a new one
      return true;
    } else {
      // Found at least one snapshot; end the workflow
      return false;
    }

UI shows a workflow step for creating a snapshot with a custom script.

The error handling Exception Handling we will be using the previously created errMachineHasSnapshot

UI shows workflow step “VM Has Snapshot?” with error icon, “Create a Snapshot” step, and error handling details.

The workflow element should look like this after selecting the Workflow Create a snapshot

UI shows workflow step for creating a snapshot with inputs and outputs.

The next step is to fix the inputs. We will be removing the Choose the VM tab by clicking on the x

VM Snapshot Input Form shows “Choose the VM” and “Enter snapshot creation parameters” fields. Error dialog warns to delete “Choose the VM” tab in vRA snapshot creation.

We will be replacing the first item with vm and the display type

Configuring virtual machine selection for snapshot creation in vRA 8.2.

It should look like this:

UI shows “vm” field with Tree Picker display type, VC:VirtualMachine reference type.

In the end we should have the following:

UI shows fields for creating a virtual machine snapshot in vRA 8.2.

Next go to Actions and click on New Action

The image shows a vRealize Automation Orchestrator interface with a highlighted “New Action” button.

Give it a Name and a Module name

UI for naming a snapshot action in vRA 8.2.

Under Script type in

var allVms = VcPlugin.getAllVirtualMachines();
for (var I in allVms) {
    if (allVms[I].name === name) {
        return allVms[I];
    }
}
return null;

A screenshot shows a script editor with a JavaScript function for finding a virtual machine by name.

Under the Return type enter VC:VirtualMachine. Under the Inputs type in name and click Create on the bottom left

In the Return type section, VC:VirtualMachine is entered. Inputs include name, with string typed and no array option.

Once were done we can save it and move on to Cloud assembly to create the resource action

Go to Cloud Assembly -> Design -> Resource Actions click on new resource action

Navigate to Cloud Assembly, select Design, then Resource Actions, and click NEW RESOURCE ACTION.

In the name field type something like CustomSnapshot, Display name VM Snapshot, give a description and toggle the activate switch to on

Configure custom resource action for VM Snapshot in vRA 8.2.

Under Resource type click on add pick Cloud.vSphere.Machine

Select “Cloud.vSphere.Machine” under “Select Resource Type” for vRA 8.2 snapshot.

Under Workflow click Add and pick VM Snapshot

Under Workflow, click Add and select VM Snapshot.

In the Property Binding pick getVmByName action and under string enter ${properties.resourceName}

Property Binding: Select ‘getVmByName’, input ’name’ as ${properties.resourceName}.

On the bottom click on edit request parameters

In the workflow step, options include “VM Snapshot” and “CHANGE”.

click on vm and change the Label to Reason and Display type to DropDown

UI shows Label “Reason” and Display type “DropDown” for a form field.

Under Values Type in the options that you want to have shown Separated by , ex: Patching,New Release

In the “Values” tab, “Patching,New Release” is entered as a constant value option.

Under Constraints make it as required by Picking Yes in the required field

In the Constraints tab, select “Yes” in the Required field to make the field mandatory.

The other fields and options can be modified as needed

Once everything is saved we can test out the Day 2 action by going to an existing deployment and trying to create a snapshot. We can see in the menu an additional option all the way to the bottom:

VM Snapshot option visible in menu.

When choosing the option we can see the custom form that we filled in earlier

VM Snapshot wizard step with options for reason, description, memory, and quiesce checkboxes.