You can manage expired deployments and their resources by using the Expire action alongside existing event topics.

After a deployment lease in your environment expires, you can use extensibility event topics to perform tasks, such as stopping the back up or monitoring of any deployment resources. To perform these day 2 operations, the VMware Aria Automation API uses a system-level Expire action. This action is triggered automatically by the system whenever a deployment lease in your organization expires. The Expire action trigger precedes the power off event for any resources associated with that deployment.
Note: In previous product releases, the power off event was triggered at the deployment level after lease expiry. Now the power off event is triggered at the resource level for each deployment resource that is in the powered on state.
The Expire action is included in the payload of existing event topics, such as Deployment action requested and Deployment action completed, and uses the deploymentid parameter to perform pre-expiry and post-expiry tasks associated with the deployment resources.
Note: The Expire action is triggered approximately 10 to 15 minutes after your deployment lease expires. The system does not trigger lease expiry events prior to the actual lease expiry. The Expire action is a system-level action and users cannot trigger the events associated with it manually.

For the current use case, you are using the Deployment action requested event topic along with the Expire action to back up a virtual machine in your deployment as a template. For this case, the back up is performed by using a Automation Orchestrator workflow but the same task can also be performed by using an extensibility action as the runnable item of the subscription.


  1. Navigate to Extensibility > Subscriptions and click New Subscription.
  2. Enter a name for the subscription.
  3. Under Status, verify that the subscription is enabled.
  4. Under Event Topic, select the Deployment action requested event topic.
  5. Toggle on the Condition option and add a filter for the expiry action: == 'Expire'
    Note: The Deployment action requested event topic can be triggered by different deployment day 2 operations, such as changing the deployment lease duration. Adding the lease expiry action filter guarantees that the subscription is triggered only for expiry events.
  6. Under Action/workflow, add the Automation Orchestrator workflow.
    The schema of this sample workflow includes a scriptable task and a workflow element which includes the Clone virtual machine, no customization workflow which comes preconfigured with Automation Orchestrator. The scriptable task element includes the following sample script:
    System.log("Lease expiry action triggered to clone a VM...")
    System.log("Deployment Id is: " + inputProperties.deploymentId);
    inputHeaders = new Properties();
    deploymentId = inputProperties.deploymentId;
    pathUriVariable = "/deployment/api/deployments/" +deploymentId +"/resources"; 
    var restClient = vRAHost.createRestClient();
    var request = restClient.createRequest("GET", pathUriVariable, null);
    var keys = inputHeaders.keys;
    for(var key in keys){
        request.setHeader(keys[key], inputHeaders.get(keys[key]));
    var response = restClient.execute(request);
    System.log("Content as string: " + response.contentAsString);
    var content = response.contentAsString;
    var obj = JSON.parse(content);
    var object = new Properties(obj);
    var contentJson = object.content;
    for (var i = 0; i < contentJson.length; i++) {
        var resources = contentJson[i];
        var resourceProperties =;
        System.log("Resource name is: " + resourceProperties.resourceName)
        resourceName = resourceProperties.resourceName;
    var query = "xpath:name='" + resourceName + "'"; 
          var vms=Server.findAllForType("VC:VirtualMachine", query); 
          System.log("VM input is: " + vcVM);
          dataStoreOutput = datastore
          template= true;
  7. Decide whether to set the subscription as blocking or non-blocking.
    Note: Making the subscription blocking means that the power off event for the deployment resources is triggered only after the runnable item, in this case the lease expiry workflow, finishes its run successfully. Making the subscription non-blocking means that power off event is triggered for the deployment resources regardless of the status of the workflow run.
  8. To finish editing the subscription, click Save.

What to do next

After the extensibility subscription is triggered by the lease expiry event and the workflow run is successful, navigate to the vSphere Web Client and validate that your virtual machine is converted to a template.