Service Composer in IBM Cloud Automation Manager provides out-of-the-box approval support during service provisioning with IBM Business Process Manager.
This blog post is intended to help clients to bring their own Workflow Manager and integrate it with IBM Cloud Automation Manager as an approval mechanism.
Using an existing Workflow Manager (i.e., ServiceNow, JIRA, etc.)
With the help of a resthook and local-exec Terraform provisioner, you can integrate a third-party Workflow Manager with the IBM Cloud Automation Manager to provide approval support in Service Composer. This solution is applicable to all those Workflow Managers that expose a REST API for placing an approval request and retrieving the state of the approval request.
The image below shows a service that has the following two components:
- Approval
- Provision
Approval
- Comprised of two activities—resthook and Terraform template.
- The resthook activity is used to send an approval request to the Workflow Manager.
- The Terraform template uses the localexec provisioner to poll for approval status from the Workflow Manager.
Provision
- Template that needs to be provisioned.
- As per the proposed solution, all the activities that need to be provisioned should be placed after the approval activities.
High-level architecture
Flow
- Send a request for an approval to the Workflow Manager. See Use Cases 1, 2, and 3 below as examples.
- Poll in specific time intervals (e.g., five seconds) to retrieve approval status from the Workflow Manager until the status is in-progress. If status becomes approve, exit; otherwise, exit with a timeout error. See Use Cases 1 and 3 below as examples.
- Start provisioning. See Use Cases 1 and 3 below as examples.
Example: Third-party Workflow Manager
For demonstration purposes, I used a REST Server to serve both the “Approval Request” and “Approval Status” APIs. The REST server acts like a third-party Workflow Manager. In your case, refer to the API documentation of the Workflow Manager that you going to integrate with IBM Cloud Automation Manager.
Below, you’ll find some sample REST APIs, shell scripts, and a Terraform template that I have used as examples.
Rest API for creating an approval request
URL: http://<rest_server_ip>:8080/adapter/icam/v1/service/provisionrequest
Method: POST
Payload:
Response:
Rest API for retrieving an approval status
URL: http://<rest_server_ip>:8080/adapter/icam/v1/service/provisionrequest/<orderNumber>
Method: GET
Response:
Script to retrieve an approval status
Terraform template with local-exec provisioner
Create a Terraform template using the previous two scripts and import the Terraform template into IBM Cloud Automation Manager.
Using the REST APIs and a Terraform template
Using the REST APIs in the previous example, create a REST server to show the Workflow Manager.
Use case 1: Approver approved an approval request
- Deploy the service:
- View service logs. Verify that the resthook activity is created and the request for approval has been sent successfully:
- View activity logs. Verify that the status received from the Workflow Manager is in-progress and, hence, polling continues:
- Approve an approval request from the Workflow Manager.
- View activity logs. Verify that the polling has stopped and the template is created successfully:
- Verify service logs. Verify that the service instance is deployed successfully and goes into an active state:
Use case 2: Approver rejected an approval request
- Deploy the service:
- View service logs. Verify that the resthook activity is created and the request for approval has been sent successfully:
- View activity logs. Verify that the status received from the Workflow Manager is in-progress and polling continues:
- Reject the approval request from the Workflow Manager.
- View activity logs. Verify that the service instance goes into Error State. As the approval request gets rejected, the polling exited with an error:
Use case 3: Polling gets timed out (i.e., the Approver didn’t approve or reject approval request within timeout limit)
- Deploy the service:
- View service logs. Verify the resthook activity is created and the request for approval has been sent successfully.
- View activity logs. Verify that the status received from the Workflow Manager is in-progress and, therefore, polling continues:
- Approver didn’t approve or reject approval request within time out. Service instance goes into Error state because of timeout:
- Retry service instance:
- View activity logs. Verify that polling gets started again:
- Approve the approval request from the Workflow Manager.
- View activity logs. Verify that the polling stopped, and the template is created successfully:
- View service logs. Verify that the service instance is deployed successfully and goes into active state:
Summary
With the help of a resthook and local-exec Terraform provisioner, we can integrate a third-party Workflow Manager with the IBM Cloud Automation Manager to provide approval support in Service Composer.
The solution is applicable to all those Workflow Managers which expose a REST API for placing an approval request and retrieving the state of approval request.
If the service provisioning fails with a timeout error, you can use the `resume` operation to restart the provisioning again.