March 19, 2020 By Sagar Jadhav 5 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

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

  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:
  2. View service logs. Verify that the resthook activity is created and the request for approval has been sent successfully:
  3. View activity logs. Verify that the status received from the Workflow Manager is in-progress and, hence, polling continues:
  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:
  6. 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

  1. Deploy the service:
  2. View service logs. Verify that the resthook activity is created and the request for approval has been sent successfully:
  3. View activity logs. Verify that the status received from the Workflow Manager is in-progress and polling continues:
  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:

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:
  2. View service logs. Verify the resthook activity is created and the request for approval has been sent successfully.
  3. View activity logs. Verify that the status received from the Workflow Manager is in-progress and, therefore, polling continues:
  4. Approver didn’t approve or reject approval request within time out. Service instance goes into Error state because of timeout:
  5. Retry service instance:
  6. View activity logs. Verify that polling gets started again:
  7. Approve the approval request from the Workflow Manager.
  8. View activity logs. Verify that the polling stopped, and the template is created successfully:
  9. 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.

Was this article helpful?
YesNo

More from Cloud

IBM Tech Now: April 8, 2024

< 1 min read - ​Welcome IBM Tech Now, our video web series featuring the latest and greatest news and announcements in the world of technology. Make sure you subscribe to our YouTube channel to be notified every time a new IBM Tech Now video is published. IBM Tech Now: Episode 96 On this episode, we're covering the following topics: IBM Cloud Logs A collaboration with IBM watsonx.ai and Anaconda IBM offerings in the G2 Spring Reports Stay plugged in You can check out the…

The advantages and disadvantages of private cloud 

6 min read - The popularity of private cloud is growing, primarily driven by the need for greater data security. Across industries like education, retail and government, organizations are choosing private cloud settings to conduct business use cases involving workloads with sensitive information and to comply with data privacy and compliance needs. In a report from Technavio (link resides outside ibm.com), the private cloud services market size is estimated to grow at a CAGR of 26.71% between 2023 and 2028, and it is forecast to increase by…

Optimize observability with IBM Cloud Logs to help improve infrastructure and app performance

5 min read - There is a dilemma facing infrastructure and app performance—as workloads generate an expanding amount of observability data, it puts increased pressure on collection tool abilities to process it all. The resulting data stress becomes expensive to manage and makes it harder to obtain actionable insights from the data itself, making it harder to have fast, effective, and cost-efficient performance management. A recent IDC study found that 57% of large enterprises are either collecting too much or too little observability data.…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters