An approval process for provisioning
Recipe 8.2 builds a VM for anyone who can run the workflow. In most teams some requests need a second person to say yes first: a large VM, a production network, anything that costs money. This recipe adds that step without changing the provisioning workflow at all.
You build Request a VM, a workflow that sits in front of Provision a VM from a template. Small VMs are approved automatically. Bigger ones send a mail to the approvers and wait, up to a deadline, for a member of OrchestratorApprovers to answer. Only an approved request reaches the provisioning workflow, and the requester gets a mail whatever the outcome: built, rejected, or expired. The rules live in a configuration element, so changing the size limit or the deadline doesn’t need a new version of the workflow.
Getting ready
- The workflow Provision a VM from a template from recipe 8.2.
- The user interaction from recipe 3.9. This recipe uses the same element, with a group of approvers.
- Mail set up as in recipe 5.5, and the action
com.vcfguide.chapter5/sendHtmlMail. - A group
OrchestratorApproversin vSphere SSO with at least one member who isn’t you, and a mail address that reaches its members, hereapprovers@vmw.lab. - Binding a variable to a configuration element, from recipe 4.7.
How to do it
Keep the rules in a configuration element
- Go to Assets > Configurations and create
vcfguide-ch8-provisioningin the folder VCF Orchestrator Guide/Chapter 8, with four variables:
| Name | Type | Value | Means |
|---|---|---|---|
autoApproveMaxCpus |
number |
2 |
Requests up to this many vCPUs… |
autoApproveMaxMemoryMb |
number |
4096 |
…and this much memory are approved automatically |
approvalHours |
number |
24 |
How long a request waits for an answer |
approverMail |
string |
approvers@vmw.lab |
Where approval requests are mailed |
- Create the action
isAutoApprovedincom.vcfguide.chapter8, with the inputscpus,memoryMb,maxCpus, andmaxMemoryMb, allnumber, and the return typeboolean:
var small = cpus <= maxCpus && memoryMb <= maxMemoryMb;System.log(cpus + " vCPU / " + memoryMb + " MB is " + (small ? "within" : "above") + " the automatic limit of " + maxCpus + " vCPU / " + maxMemoryMb + " MB");return small;Set up the workflow
- Create the workflow Request a VM in VCF Orchestrator Guide/Chapter 8. On Inputs/Outputs, add the same eight inputs as Provision a VM from a template (
template,vmName,folder,cluster,datastore,specName,cpus,memoryMb), plusrequesterMailandreason, bothstring. Add the outputsvm(VC:VirtualMachine),ipAddress(string), andoutcome(string). - On the Variables tab, add the four settings, each bound to the variable of the same name in
vcfguide-ch8-provisioning, as in recipe 4.7. Then add the working variables:
| Name | Type | Holds |
|---|---|---|
needsApproval |
boolean |
Whether the request goes to an approver |
approvalDeadline |
Date |
When the request stops waiting |
approved |
boolean |
The approver’s answer |
approverComment |
string |
The approver’s reason |
approvalError |
string |
The error when nobody answers in time |
Decide whether to ask
- On the Schema tab, add a scriptable task
Check the request, withcpus,memoryMb,autoApproveMaxCpus,autoApproveMaxMemoryMb, andapprovalHoursin, andneedsApprovalandapprovalDeadlineout:
var auto = System.getModule("com.vcfguide.chapter8").isAutoApproved( cpus, memoryMb, autoApproveMaxCpus, autoApproveMaxMemoryMb);needsApproval = !auto;approvalDeadline = new Date(new Date().getTime() + approvalHours * 60 * 60 * 1000);if (needsApproval) { System.log("Approval needed by " + approvalDeadline);}- Add a decision
Needs approval?after it, testingneedsApproval. Its false branch goes straight to the provisioning step you add in step 12.
Ask the approvers
- On the true branch, add a scriptable task
Mail the approvers, withapproverMail,vmName,template,cpus,memoryMb,reason,requesterMail, andapprovalDeadlinein:
function esc(text) { return String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");}var html = "<p>A VM request is waiting for your approval.</p>" + "<table>" + "<tr><td>VM name</td><td>" + esc(vmName) + "</td></tr>" + "<tr><td>Template</td><td>" + esc(template.name) + "</td></tr>" + "<tr><td>Size</td><td>" + cpus + " vCPU, " + memoryMb + " MB</td></tr>" + "<tr><td>Requested by</td><td>" + esc(requesterMail) + "</td></tr>" + "<tr><td>Reason</td><td>" + esc(reason) + "</td></tr>" + "<tr><td>Answer by</td><td>" + esc(approvalDeadline.toString()) + "</td></tr>" + "</table>" + "<p>Answer it in the Orchestrator Client, under Activity > Waiting for Input: " + "<a href=\"https://vco01.vmw.lab/orchestration-ui/\">https://vco01.vmw.lab/orchestration-ui/</a></p>" + "<p>Run ID: " + workflow.id + "</p>";
System.getModule("com.vcfguide.chapter5").sendHtmlMail( approverMail, "Approval needed: VM " + vmName, html);- After it, add a User interaction called
Ask for approval, as in recipe 3.9: bindtimeout.datetoapprovalDeadline, addapprovedandapproverCommentas its form inputs, label themApprove this requestandReason, and makeReasonrequired. - Restrict who can answer. Bind
security.assignee.groupsto a value that holds the groupOrchestratorApprovers. Only its members, and Orchestrator administrators, can answer.
security.assignee.groups a fixed group (a variable of the group type with a value picked from vSphere SSO, or a value set on the element), record the type name, and confirm that a member of OrchestratorApprovers can answer and that a user outside it, including the requester, can’t. Check the client’s URL in the mail (/orchestration-ui/) and that workflow.id in a scriptable task returns the run’s ID.- Add a decision
Approved?after the user interaction, testingapproved. On its false branch, add a scriptable taskTell the requester: rejected, withrequesterMail,vmName, andapproverCommentin andoutcomeout, and connect it to an end element:
outcome = "Rejected: " + approverComment;System.getModule("com.vcfguide.chapter5").sendHtmlMail(requesterMail, "VM " + vmName + " was not approved", "<p>Your request for " + vmName + " was rejected.</p><p>Reason: " + approverComment.replace(/</g, "<") + "</p>");System.log(outcome);- Draw the exception path of
Ask for approvalto a scriptable taskTell the requester: expired, binding the error toapprovalError, as in recipe 3.9. It setsoutcometoExpired: nobody answered byplus the deadline, mails the requester, and ends.
Build and report
- Drag the workflow Provision a VM from a template onto the schema, where the true branch of
Approved?and the false branch ofNeeds approval?meet. Bind its eight inputs to the workflow inputs of the same name, and its outputsvmandipAddressto the workflow outputs. - After it, add a scriptable task
Tell the requester: ready, withrequesterMail,vm, andipAddressin andoutcomeout. It setsoutcometoBuilt:plus the VM’s name and address, and mails the same text to the requester.
Full Schema of Request a VM: Check the request, Needs approval?; true branch Mail the approvers → Ask for approval → Approved?, with Tell the requester: rejected on false and a red dashed exception arrow from Ask for approval to Tell the requester: expired; false branch of Needs approval? and true branch of Approved? both into the workflow element Provision a VM from a template → Tell the requester: ready.
Try every path
- Run Request a VM with
vcfguide-web-02, 1 vCPU, 2048 MB, and your own mail address asrequesterMail. It skips the approval, builds the VM, and mails you Built. - Run it again with
vcfguide-web-03and 4 vCPU. The run stops in Waiting, and the approvers’ mailbox has Approval needed: VM vcfguide-web-03. - Log in as a member of
OrchestratorApprovers, open Activity > Waiting for Input, select the request, choose Approve this request, enter a reason, and answer. The run carries on into Provision a VM from a template, and you get the Built mail. - Run it a third time with
vcfguide-web-04and 4 vCPU, and answer with Approve this request cleared and the reasonToo large for the lab. No VM is built, and the not approved mail carries the reason. - To see the expiry path without waiting a day, set
approvalHoursinvcfguide-ch8-provisioningto0.05, requestvcfguide-web-05with 4 vCPU, and don’t answer. About three minutes later the run follows the exception path and you get the Expired mail. SetapprovalHoursback to24. - Delete
vcfguide-web-02andvcfguide-web-03.
Logged in as a member of OrchestratorApprovers: Activity > Waiting for Input with the Request a VM run for vcfguide-web-03, answer form open with Approve this request selected and Reason filled; beside it the approval mail with the request table and the link.
Activity > Workflow Runs filtered on Request a VM: four completed runs; Variables tab of each, or a composite, with outcome = Built: vcfguide-web-02 …, Built: vcfguide-web-03 …, Rejected: Too large for the lab, Expired: nobody answered by ….
How it works
Two workflows, two jobs. Provision a VM from a template knows how to build a VM. Request a VM knows who may ask for one and who has to agree. Keeping them apart means the provisioning workflow can still be called directly, by a pipeline or by VCF Automation, which have their own controls, and the approval rules can change without a new version of the build.
The wait costs nothing. While a request waits for an answer, the run is saved in Orchestrator’s database and holds no thread, as recipe 3.9 explains. A day’s deadline, or a hundred requests waiting at once, doesn’t load the server. A restart doesn’t lose them.
The mail doesn’t answer anything. The mail tells the approvers that a request exists. The answer itself is given in the Orchestrator Client, or through the REST API, where Orchestrator checks that the person is allowed to answer. Someone who forwards the mail can’t approve the request by doing so.
Rules as data. The limits and the deadline are read from vcfguide-ch8-provisioning when each run starts. Changing them is a change to a configuration element, which version history records (recipe 6.1), and which can differ between a development and a production Orchestrator when you promote the workflow (recipe 6.4).
There's more
Requests from the VCF Automation catalog. When users order VMs from the VCF Automation catalog, don’t build the approval in Orchestrator. Use VCF Automation’s approval policies, which decide which requests need approval and who answers, and are answered in VCF Automation. In 9.1 they also have an API: the VM Apps organization’s Approval Service lists, approves, and rejects approval requests and manages approval policies. An Orchestrator workflow in that setup does the build and the steps around it, and the approval stays in one place. Broadcom KB 438602 is a warning for workflows that create approval policies themselves during a request: on 8.x the policy could take effect too late for the request that created it, and the KB adds a pause after the call.
The policy service of a VCF Automation 9.1 VM Apps organization (GET /policy/api/policyTypes) lists six policy types: Approval Policy (com.vmware.policy.approval), Lease Policy, Day 2 Actions Policy, Content Sharing Policy, Deployment Limit Policy and Resource Quota Policy. So approvals in VCF Automation are there, as their own policy type, next to the approvals you build in Orchestrator.
Remind and escalate. A request that expires because the only approver is on holiday isn’t a good outcome. Instead of one long wait, wait half the time, then mail a reminder to the same group or a manager’s group, and wait again with a second user interaction. The second interaction can have a different security.assignee.groups.
Answer from somewhere else. Approvers who live in a ticketing tool or a chat client don’t need to open Orchestrator. Recipe 3.9 shows the REST call that answers a user interaction. A small integration on the ticket or chat side can make that call when someone clicks Approve, with an account that’s allowed to answer.
Ask the approver for more. The answer form can ask for more than yes or no. An approver could pick the datastore, or cut the memory to what they’re willing to approve, and Request a VM passes the answer on to the build instead of the requested value.
Four eyes. Orchestrator administrators can answer any user interaction. If your process says the requester must never approve their own request, don’t rely on the group alone: in Check the request, record Server.getRunningUser(), and after the answer compare it with the person who answered, if the run records them (see the lab check above), and reject the request when they’re the same.
See also
- 3.9 User interactions and approvals, for the user interaction element and answering through the REST API.
- 4.7 Configuration elements in code, for binding variables to a configuration element.
- 5.5 Sending and reading mail, for
sendHtmlMail. - 8.2 Provisioning a VM from a template, the workflow this one calls.
- Broadcom TechDocs (VCF 9.0): Set the user interaction security.group variable, Set the timeout.date variable to an absolute date, Define user interaction exception behavior, and Call a workflow synchronously.
- Broadcom developer portal: VCF Automation API 9.1, VM Apps organization Approval Service.
- Broadcom KB 438602: an approval policy created through the API during a deployment isn’t applied.
- CloudBlogger, the author’s blog: Workflow to automatically approve your VCF Automation Inbox pending approvals.
