The Simplest Way to Make Step Functions and Terraform Work Like They Should
Teams use step functions and terraform to build and run cloud workflows from code. Terraform sets up the state machines and roles, while Step Functions runs each task in order. This pair turns manual cloud jobs into repeatable steps that teams can review in version control. When you define your workflow in code, every change goes through a peer check first. You also avoid manual clicks in the cloud console that cause drift over time. How step functions and terraform share roles and data Two
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Teams use step functions and terraform to build and run cloud workflows from code. Terraform sets up the state machines and roles, while Step Functions runs each task in order.
This pair turns manual cloud jobs into repeatable steps that teams can review in version control. When you define your workflow in code, every change goes through a peer check first. You also avoid manual clicks in the cloud console that cause drift over time.
How step functions and terraform share roles and data
Two distinct roles handle the work when you pair step functions and terraform in production. The deploy tool uses a build role to create the state machine and its rules. The state machine then uses its own runtime role to call other cloud services.
Keep these two roles separate so your deploy tool only sets up the cloud resources. Your workflow definitions can load Dynamic ARNs from your state files during a deploy run. This approach stops teams from hardcoding account numbers or service names inside workflow text files.
When the state machine runs, it passes small JSON payloads from one step to the next. If a payload holds emails, phone numbers, or card numbers, limit who can read run history. Data masking rewrites matched fields in results so sensitive strings stay safe during debug work.
Common failure modes and how to scope roles
Many teams fail by giving one giant admin role to both the build tool and workflow. If a single task breaks or gets tricked, that broad role puts every cloud resource at risk. Shared service accounts also make it hard to see which person or job changed a resource.
Another common bug happens when teams write state machine definitions as giant raw text blocks. One typo in a service name will pass the deploy step but fail at runtime. Instead, link each workflow task to the exact resource output created by your code templates.
Cloud Functions IAM + Terraform Security (tfsec, Checkov): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Scope each state machine role down to the exact actions and resources its tasks need. If a workflow only runs two functions and writes to one queue, grant only those rights. Put your compute tasks inside private subnets and restrict outbound traffic to known internal endpoints.
How to log and test workflow changes safely
Unlogged workflow runs leave your team blind when a multi-step job stalls at night. Turn on run history logs and send them to a central log group with retention rules. Make sure your deploy templates create the log group before the state machine starts running.
Watch out for high log bills when you run high-volume workflows that process thousands of items. Set your log level to record errors and state changes rather than every raw payload. You can turn on full step logs in test accounts while keeping production logs lean.
Test your workflow logic and your role permissions in a staging account before every production release. Automated checks can verify that your deploy plan does not drop active state machines by mistake. When a state machine updates, let running jobs finish on the old version while new jobs use the new rules.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Should I store state machine JSON inside my deploy files?
Keep the workflow definition in its own template file and pass resource names in as variables. This keeps your code clean and lets your editor check the syntax before you deploy.
How do I stop my deploy tool from breaking active workflow runs?
Use versioned state machine runs and avoid changes that force a full replacement of the resource. Standard workflows let active runs finish even if you update the definition during the day.
What is the safest way to grant permissions to a state machine?
Create one dedicated role per state machine and list only the specific tasks it must call. Never reuse the same broad role across multiple workflows or across different cloud accounts.
Related guides
In this post