Use your existing Workflow Manager with IBM Cloud Automation Manager

Sagar Jadhav
IBM Cloud
Published in
6 min readMar 19, 2020

Service Composer in IBM Cloud Automation Manager provides an out of the box approval support during service provisioning with IBM Business Process Manager. The blog is intended to help clients to bring their own Workflow Manager and integrate it with IBM Cloud Automation Manager for approval mechanism.

Q: “I already have my own Workflow Manager, can I use it?”

A: The good news…. “Yes, you can, read on to learn how!”

Using an existing Workflow Manager (for example: ServiceNow, JIRA, or another)

  1. With the help of resthook and local-exec terraform provisioner, you can integrate a 3rd Party workflow manager with the IBM Cloud Automation Manager to provide approval support in service composer.
  2. This 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.

The following image shows a service, which has the following two components :

1. Approval

2. Provision

Service

Approval:
1. It comprises of two activities: resthook and Terraform template.
2. resthook activity is used to send an approval request to the Workflow Manager.
3. Terraform template uses the local-exec provisioner to poll for approval status from the Workflow Manager.

Provision:
1. Template that needs to be provisioned.
2. As per the proposed solution, all the activities that need to be provisioned should be placed after the approval activities.

High Level Architecture

Solution Architecture

Flow:

1. Send request for an approval to Workflow Manager. See use cases 1,2 and 3 as examples.

2. Poll in specific time interval (let say 5 seconds) to retrieve approval status from the Workflow Manager until status is in-progress. If status becomes approve, exit, otherwise exit with timeout error. See use cases 1 and 3 as examples.

3. Start provisioning. See use cases 1 and 3 as examples.

Example: 3rd Party Workflow Manager

For demonstration purposes, I used a REST Server to serve both the “Approval Request” and “Approval Status” API’s. The REST server acts like a 3rd Party workflow manager. In your case refer to the API documentation of workflow manager that you are going to integrate with IBM Cloud Automation Manager.

Please find below sample REST API’s, shell script and a terraform template, which I have used to demonstrate:

Rest API for creating an approval request:

URL: http://<rest_server_ip>:8080/adapter/icam/v1/service/provisionrequest

{“serviceInstanceName”: “xyz”}

Response:

{“orderNumber”: “123456”}

Rest API for retrieving an approval status:

URL: http://<rest_server_ip>:8080/adapter/icam/v1/service/provisionrequest/<orderNumber>

Method: GET

Response:

{“status”: “in-progress”}

Script to retrieve an approval status:

#!/bin/shresult=$(curl -X GET --header "Accept: */*" "http://<rest_server_ip>:8080/adapter/icam/v1/service/provisionrequest/$1" | jq -r '.status' )
while [ "$result" = "in-progress" ]
do
echo $result
result=$(curl -X GET --header "Accept: */*" "http://<rest_server_ip>:8080/adapter/icam/v1/service/provisionrequest/$1" | jq -r '.status')
sleep 5
done
if [ "$result" = "approve" ]
then
exit 0
else
exit 1

Terraform Template with local-exec provisioner

variable "order_number" {type = string}resource "null_resource" "tempResource" {provisioner "local-exec" {command = "/bin/bash req.sh ${var.order_number}"}}

Create a terraform template using the previous two scripts and import terraform template in IBM Cloud Automation Manager.

Let me show you using the REST APIs and a Terraform template

Using the example REST APIs in the previous example, create a REST server to show workflow manager.

Use Case 1: Approver approved an approval request.

Step 1: Deploy the service.

Step 2: View service logs.

Verify that the resthook activity is created and a request for approval is sent successfully.

Step 3: View activity logs.

Verify that the status received from the Workflow Manager is in-progress and hence polling continues.

Step 4: Approve an approval request from Workflow Manager.

Step 5: View activity logs.

Verify that the polling is stopped and the template is created successfully.

Step 6: Verify service logs.

Verify that service instance is deployed successfully and goes into an active state.

Use Case 2: Approver rejected an approval request.

Step 1: Deploy the service.

Step 2: View service logs.

Verify that the resthook activity is created and a request for approval is sent successfully.

Step 3: View activity logs.

Verify that the status received from Workflow Manager is in-progress and hence polling continues.

Step 4: Reject the approval request from the Workflow Manager.

Step 5: View activity logs.

Verify that the service instance goes into Error State. As the approval request gets rejected, polling exited with an error.

Use Case 3: Polling gets timed out, which means, the Approver didn’t approve or reject approval request within timeout limit.

Step 1: Deploy the service.

Step 2: View service logs.

Verify that the resthook activity is created and a request for approval is sent successfully.

Step 3: View activity logs.

Verify that the status received from the Workflow Manager is in-progress and hence polling continues.

Step 4: Approver didn’t approve or reject approval request within time out.

Service instance goes into Error state because of timeout.

Step 5: Retry service instance.

Step 6: View activity logs.

Verify that polling gets started again.

Step 7: Approve the approval request from the Workflow Manager.

Step 8: View activity logs.

Verify that the polling stopped and the template is created successfully.

Step 9: View service logs.

Verify that the service instance is deployed successfully and goes into an active state.

References:

1. Learn more about terraform local-exec at https://www.terraform.io/docs/provisioners/local-exec.html.
2. Learn more about how to use resthook in IBM Cloud Automation Manager at https://www.ibm.com/support/knowledgecenter/SS2L37_4.1.0.0/cam_resthooks.html.
3. Learn more about managing template in IBM Cloud Automation Manager at https://www.ibm.com/support/knowledgecenter/SS2L37_4.1.0.0/cam_creating_template.html.

--

--

Sagar Jadhav
IBM Cloud

Backend Developer (Cloud ☁️), IBM India Software Labs | 👨🏻‍💻 Speaker | Red Hat Certified OpenShift Administrator