The Simplest Way to Make Github and Terraform Work Like They Should
Teams use github and terraform together to manage cloud setups through code reviews. GitHub stores the code and runs checks, while Terraform builds the cloud resources. This pairing lets engineers review changes in a pull request before anything goes live. Every cloud update gets a clear record of who wrote it and who approved it. When set up well, your main branch always matches your real cloud state. How github and terraform share roles and data The workflow starts when an engineer opens a
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 github and terraform together to manage cloud setups through code reviews. GitHub stores the code and runs checks, while Terraform builds the cloud resources.
This pairing lets engineers review changes in a pull request before anything goes live. Every cloud update gets a clear record of who wrote it and who approved it. When set up well, your main branch always matches your real cloud state.
How github and terraform share roles and data
The workflow starts when an engineer opens a pull request in GitHub. A runner starts up and checks out the latest branch code. The runner then needs a way to log in to your cloud provider.
Modern setups use OpenID Connect so GitHub can request a short token from the cloud. GitHub sends a signed token that proves which repo and branch started the run. Your cloud provider checks this token against a trust rule and grants a role.
Next, Terraform reads the remote state file from a shared storage bucket. It compares your branch code against the state file and the live cloud APIs. Terraform then writes a plan summary back to the pull request as a comment.
Teammates read that comment to check what will change before they approve the merge. Once someone merges the pull request, a new job runs on the main branch. That job takes a write role, applies the plan, and updates the state file.
Common failure modes and how to scope roles
Many teams start by putting static cloud keys into GitHub secrets. Static keys do not expire on their own and often hold broad admin rights. If a bad actor steals that key, they can delete or read anything.
Another common mistake is using the same cloud role for plans and applies. If a pull request job has write permissions, untrusted branch code can change live systems. A someone could open a pull request that alters cloud settings before anyone approves it.
Terraform Security (tfsec, Checkov) + GitHub Actions Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Shared state files also create huge risks when one file holds the whole company setup. A small typo in one pull request can lock the state for every other team. Worse, the state file often holds raw database passwords and API keys in plain text.
To fix these risks, split your cloud roles into two distinct levels. Give pull request jobs a read-only role that can only run a plan. Give main branch jobs a write role, and lock it to that single branch.
You should also break large state files into smaller pieces by app or stage. Put dev, staging, and prod into separate state buckets with separate cloud roles. Make sure only the runner role and a break-glass admin role can read state buckets.
Keeping state locks and branch rules in sync
Concurrent runs can corrupt your state if two merges happen at the same time. Always turn on state locking in your storage backend so only one run happens at once. Configure your GitHub workflow to queue jobs on the main branch instead of running them together.
Branch protection rules in GitHub are the other half of a safe setup. Require at least one human review and a passing plan check before anyone can merge. When a plan goes stale, require the branch to update before the merge button works.
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 Terraform plan jobs use the same role as apply jobs?
No, plan jobs on pull requests should only use a read-only cloud role. Only apply jobs on your protected main branch should get a role that can write changes.
Where should teams store the Terraform state file?
Store the state file in a remote cloud bucket that supports state locking and encryption. Never commit state files to GitHub because they often contain raw secrets in plain text.
How do we stop two pull requests from conflicting?
Turn on state locking in your backend and set GitHub to run one job at a time. Require branches to be up to date with main before anyone can merge them.
Related guides
In this post