vRealize Automation 7 External Approval Policy with vRealize Orchestrator Workflow
With vRealize Automation 7 an Approval Policy can be linked to an event subscription that in turn can trigger a vRealize Orchestator workflow to perform an external approval process. In this article I describe how to setup the Workflow, the Approval Policy and the Event Subscription.
This article is based on the vRealize Automation 7 Documentation where a scenario is described for an external approval:
I have modified that scenario to create a workflow approval for Virtual Machine requests and added more clarification and the necessary code examples to build it yourself.
In this working example I use a vRealize Orchestrator Workflow with a User Interaction element to handle the approval request. But you can of course modify this behavior to have the vRO Workflow send the request to an external system, for example via the HTTP Rest API and wait for the approval result.
The first step is to build the vRealize Orchestrator Workflow, that will look like this:
The workflow uses the attributes from the next image to store data during the workflow.
The workflow requires one input parameter. In the next image it is named payload and it is of the type Properties. This is a composite data type that will contain all fields coming from vRA.
There are two required output parameters: approved, a boolean to report the approval decision (yes/no) back to vRA and fieldValues of the Properties type that will contain the Business Justification for the approvers response to the request.
The first scripting element in the workflow gets the required data from the payload properties object that came from vRA.
//get the Properties-object with the requestinfo var requestInfo = new Properties; requestInfo = payload.get("requestInfo"); //get the info we need from the request itemName = requestInfo.get("itemName"); reason = requestInfo.get("reason"); requestedBy = requestInfo.get("requestedBy"); description = requestInfo.get("description");
This next element is the User Interaction element. It requires the two External Inputs from the next image: approved and businessJustification.
You can also add the other fields that are updated in the previous scripting element as Attributes that you can use in the Presentation of this element.
The third and final element is a scripting element that will update the fieldValues output parameter with the businessJustification answer form the approver.
//put the business justification in the fieldValues //properties object and set it as an output parameter var fieldValues = new Properties; fieldValues.put("businessJustification",businessJustification);
Now that we have the vRealize Orchestrator Workflow in place it's time to setup the Approval Policy. Login to the vRealize Automation Console and from the Administration tab select Approval Policies and click the green plus-sign to create a new policy. Choose a policy for a Service Catalog Item Request for a Virtual Machine. This is necessary for this example because it is based on VMs but you can of course also build policies for other types of requests.
Provide a name for the policy and click the green plus-sign
In this example I use a Pre Approval level that will only provision a machine after the request has been approved. In the next image you see that I have configured the policy to always require approval. You can of course use conditions for when you need approval. The most important setting is on the right hand side of the image, which is the Use event subscription setting, which is new in version 7.
Don't forget to set the policy to Active.
After saving the Approval Policy go to the Events item in the Administration menu to create a new subscription. The type you need to select for this example is a Pre Approval event topic.
It is possible to subscribe to the event and execute your workflow for all requests, but in this example I have limited it to Virtual Machines only with the condition from the image below.
In the next step point to the vRealize Orchestrator Workflow you have created earlier.
In the final step provide a name for the subscription.
Now that you have the policy and the subscription configured add the Approval Policy to a service or catalog item in the Service entitlement.
Now it is time to request a new item. The description and reason will be sent to the vRealize `orchestrator workflow.
Here is the request in vRealize Orchestrator:
For the user to see the result open the Items list, click on the request number at the beginning of the line and in the request details window click on the Rejected link on the left to see the result of the approval process.
The user will also receive a message about the approval process if notifications and the email server have been configured.