Run Controls Using Scripts

In this guide, you will batch re-run controls in an error state using scripts from the guardrails-samples repository.

When many controls encounter errors simultaneously, due to network outages, credential expirations, or API rate limits, re-running them one at a time through the console is impractical. The run-controls script automates this by querying for affected controls and re-running them in batches.

Prerequisites

Step 1: Identify the Affected Controls

Select Controls in the sidebar and drill into the provider you want to target. On the node's Controls tab, switch the scope to Descendant, then use the State filter to select Error (or the state you want to target). Note which control types are affected, since you'll need the Control Type URI in the next step.

Controls list filtered to Error state, showing repeated CMDB errors

Step 2: Find the Control Type URI

Select an affected control to open its detail page, then select the Developers tab. The Identifiers panel lists the control's identifiers, each with a copy button.

Control Developers tab showing the Identifiers panel with the Control Type URI

Copy the CONTROL TYPE URI value for use in the script filter. For example:

tmod:@turbot/gcp#/control/types/organizationPolicyCmdb

[!TIP] The same tab also gives you ready-made GraphQL, Steampipe, CLI, and Terraform snippets for this control, each preloaded with its identifiers.

Step 3: Clone the Guardrails Samples Repository

git clone https://github.com/turbot/guardrails-samples.git
cd guardrails-samples/guardrails_utilities/shell_utils/run-controls

Step 4: Set Environment Variables

export TURBOT_WORKSPACE="https://<your-workspace>.cloud.turbot.com/"
export TURBOT_ACCESS_KEY_ID=<your-access-key-id>
export TURBOT_SECRET_ACCESS_KEY=<your-secret-access-key>

Step 5: Run the Script

Execute the script with the --filter flag using the Control Type URI from Step 2. The --batch-size flag controls how many controls are re-run at once (25 is recommended to avoid database load).

./run-controls.sh \
  --filter 'state:error controlTypeId:<control-type-uri>' \
  --batch-size 25

For example:

./run-controls.sh \
  --filter 'state:error controlTypeId:tmod:@turbot/gcp#/control/types/organizationPolicyCmdb' \
  --batch-size 25

The script outputs progress as it re-runs each control:

[INFO] Control 1 of 22
[INFO]    Type: "CMDB"
[INFO]    Resource: "storage.uniformBucketLevelAccess"
[INFO]    State: "error"
[INFO]    Reason: "Bad Request: Error processing runnable input"
[INFO]    ID: "386400110733138"
...
[INFO] Total amount of controls re-run: 22
[INFO] Total time taken 7 second(s)

Step 6: Review

Return to the Controls page in the console and verify that the re-run controls have moved to OK.

[!TIP] To re-run policies instead of controls, use the run-policies script in the same directory with the same filter syntax.

Troubleshooting

IssueDescriptionGuide
Script fails to authenticateEnvironment variables may not be set correctly.Verify TURBOT_WORKSPACE, TURBOT_ACCESS_KEY_ID, and TURBOT_SECRET_ACCESS_KEY.
Controls return to Error after re-runThe underlying issue persists.Check control logs at Debug level for the root cause.
Script hangs or times outAPI rate limiting or network issues.Reduce --batch-size to 10 or 5 and retry.
Further assistanceIf the issue persists.Open a Support Ticket