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
Turbot/Operatorpermissions at the Turbot resource level.- Turbot Guardrails CLI installed and configured with API credentials.
- Git installed to clone the guardrails-samples repository.
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.

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.

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.
- Filter by the same control type and verify no controls remain in Error state.
- If controls return to Error after re-running, the underlying issue (credentials, permissions, network) has not been resolved.
- Check the control logs for persistent errors.
[!TIP] To re-run policies instead of controls, use the
run-policiesscript in the same directory with the same filter syntax.
Troubleshooting
| Issue | Description | Guide |
|---|---|---|
| Script fails to authenticate | Environment variables may not be set correctly. | Verify TURBOT_WORKSPACE, TURBOT_ACCESS_KEY_ID, and TURBOT_SECRET_ACCESS_KEY. |
| Controls return to Error after re-run | The underlying issue persists. | Check control logs at Debug level for the root cause. |
| Script hangs or times out | API rate limiting or network issues. | Reduce --batch-size to 10 or 5 and retry. |
| Further assistance | If the issue persists. | Open a Support Ticket |