Companion demo for the tutorial Query before you mutate: how agents should touch your infrastructure.
The example demonstrates a simple infrastructure control loop using Google Cloud Storage:
- Query live state
- Identify resources that differ from policy
- Apply bounded policy gates
- Mutate only non-compliant resources
- Query again to verify convergence
- Skip mutation when the resource is already compliant
The policy for this demo requires GCS buckets to use a customer-managed Cloud KMS key (CMEK).
Buckets where encryption is NULL are using Google-managed encryption.
The demo queries the live GCS API, identifies buckets that do not satisfy the policy, checks location and resource-count gates, applies CMEK, and verifies the resulting state.
- Docker
- Google Cloud project
- Service account credentials with permission to read and update Cloud Storage buckets
- Existing Cloud KMS key
- stackql
This demo uses:
google.storage.buckets
Pull the validated Google provider version:
REGISTRY PULL google v26.07.00432;Follow the SQL statements in:
queries.sql
Before running them, replace:
your-project-iddemo-app-bucket1your-ringyour-key
with values from your Google Cloud environment.
The flow is:
live query -> policy check -> bounded gate -> mutation -> verification -> repeat safely
The important property is that every execution begins by querying current cloud state.
A previous state snapshot can describe what was managed before. The live API describes what exists now.
The same pattern can be exposed to an agent through the StackQL MCP server.
An MCP-capable client can use StackQL to query the same live cloud APIs and reason over the results before taking an allowed action.
The SQL walkthrough in this folder keeps the underlying query, gate, mutation, and verification steps explicit.