Use Your Existing Workflow Manager with IBM Cloud Automation Manager

3 min read

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:

  1. Approval
  2. Provision
The figure above shows a service composed of two components: Approval and 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

High-level architecture

Flow

  1. Send a request for an approval to the Workflow Manager. See Use Cases 1, 2, and 3 below as examples.
  2. 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.
  3. 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:

{
“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/sh

result=$(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 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

  1. Deploy the service:
    ss3
  2. View service logs. Verify that the resthook activity is created and the request for approval has been sent successfully:
    ss4
  3. View activity logs. Verify that the status received from the Workflow Manager is in-progress and, hence, polling continues:
    ss5
  4. Approve an approval request from the Workflow Manager.
  5. View activity logs. Verify that the polling has stopped and the template is created successfully:
    ss6
  6. Verify service logs. Verify that the service instance is deployed successfully and goes into an active state:
    ss7

Use case 2: Approver rejected an approval request

  1. Deploy the service:
    ss8
  2. View service logs. Verify that the resthook activity is created and the request for approval has been sent successfully:
    ss9
  3. View activity logs. Verify that the status received from the Workflow Manager is in-progress and polling continues:
    ss10
  4. Reject the approval request from the Workflow Manager.
  5. View activity logs. Verify that the service instance goes into Error State. As the approval request gets rejected, the polling exited with an error:
    ss11

Use case 3: Polling gets timed out (i.e., the Approver didn’t approve or reject approval request within timeout limit)

  1. Deploy the service:
    ss12
  2. View service logs. Verify the resthook activity is created and the request for approval has been sent successfully.
    ss13
  3. View activity logs. Verify that the status received from the Workflow Manager is in-progress and, therefore, polling continues:
    ss14
  4. Approver didn’t approve or reject approval request within time out. Service instance goes into Error state because of timeout:
    ss15
  5. Retry service instance:
    ss16
  6. View activity logs. Verify that polling gets started again:
    ss17
  7. Approve the approval request from the Workflow Manager.
  8. View activity logs. Verify that the polling stopped, and the template is created successfully:
    ss18
  9. View service logs. Verify that the service instance is deployed successfully and goes into active state:
    ss19

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.

Be the first to hear about news, product updates, and innovation from IBM Cloud