StackGuardian Workflow Run Facts #109
arunim2405
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
StackGuardian Workflow Run Facts
What are Workflow Run Facts?
Each Workflow Run on StackGuardian could produce different types of data related to the workload that it executed including but not limited to Policy Evaluations, Cost Estimations, Resource Drifts, Resources Deployed. While the Workflow Run object has reference to the facts it generates, the reference to most recent and relevant facts are stored in the Workflow object under their respective keys as mentioned below. The latest Workflow Run Facts are Workflow Step dependent hence can be created by several Workflow Runs.
How to get a Workflow Run Fact?
The reference to the latest version of a Workflow Run Fact of each type is stored in the Workflow Object. Each workflow run fact is assigned a type and the reference to the fact is stored under that key. The reference once retrieved can then be used to get the data by making another API call inside that fact.
Depending on the storage backend used and size of the data, the reference could return the data directly or another reference which is usually a AWS S3 or Azure Blob Storage signed URL with validity. The signed URL can be used to make a request to the get the fact data.
Steps to follow when workflow run fact data is located on AWS S3 or Azure Blob Storage:
Get the Workflow using the Read Workflow API
Look for the reference to the fact type in the relevant key. The following keys are currently supported:
Inside these keys you will find a key call
workflowRunFactId
which will have the ParentId and ResourceId of the given Workflow Run FactFetch the Workflow Run Fact using Read Workflow Run Facts API . For example, the get url for the above Run Fact would be
https://api.app.stackguardian.io/api/v1/orgs/wicked-hop/wfgrps/webinar/wfs/wf-extraordinary-peach-prod/wfruns/574rgpzngm9w/wfrunfacts/default/
Use the signed URL inside the
msg
key to make another request to get the Workflow Run Fact data.The fact data can be found inside the same key of the Workflow Run Fact as the one in step 2. Please note that the other fact types mentioned in the data may be obsolete.
Example Use Case: Getting Drift Details of a Terraform Workflow
In this example, we are building a solution using StackGuardian Webhooks to process an event when a drift is detected in a Terraform Workflow and resolved.
We will start by setting up a webhook in a Terraform workflow to get the resources drift details as well as the Terraform State every time a drift is detected. In addition to determining if the drift is resolved, we will also set up webhooks on completion of Workflow Run to get notified when a drift is resolved for example by running an apply to reconcile the drift or refresh to accept the drift in the state file.
Example Drift Webhook Payload:
You can use this data to extract the Workflow Group Id and the workflow Id to get the workflow and fetch the updated Terraform State Workflow Run Fact
GET: https://api.app.stackguardian.io/api/v1/orgs/of-the-galaxy/wfgrps/App-Team-Dev/wfs/ec2-test/
Use the TfStateCleaned key to get the Workflow Run Fact as described above to get the updated State cleaned of resources and get the individual ARNs of drifted resources
Example of TfStateCleaned Object
Similarly we can set up a webhook for when a workflow is completed, we can use the COMPLETED webhook to get information when the drift is cleared. In the example payload below, we can check if
WorkflowRun.WfrunDetails.RuntimeParameters.terraformAction.action == "apply"
And clear the drift on any resources of this workflowBeta Was this translation helpful? Give feedback.
All reactions