The Simplest Way to Make Github and OpenTofu Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair github and opentofu to turn code changes into live cloud changes. This setup lets teams review stack plans in pull requests before anything runs. GitHub stores your code files and runs your workflow jobs on a schedule. OpenTofu reads those files and talks to cloud APIs to build servers and databases. When you link them well, every cloud change leaves a clear paper trail. How github and opentofu share roles and data The link between github and opentofu 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.

You pair github and opentofu to turn code changes into live cloud changes. This setup lets teams review stack plans in pull requests before anything runs.

GitHub stores your code files and runs your workflow jobs on a schedule. OpenTofu reads those files and talks to cloud APIs to build servers and databases. When you link them well, every cloud change leaves a clear paper trail.

How github and opentofu share roles and data

The link between github and opentofu starts when an engineer opens a pull request. GitHub starts a runner job that checks out the latest code branch. The runner then calls OpenTofu to compare the code against the real cloud state.

To do this check, OpenTofu needs permission to read your cloud accounts and state storage. Teams often use OpenID Connect so GitHub can trade a job token for a cloud role. This setup avoids storing static cloud keys inside your repo settings.

Once OpenTofu gets the cloud role, it pulls the state file from remote storage. It calculates the diff and sends a plan output back to the GitHub pull request. Reviewers read the plan, approve the code, and merge the branch to main. That merge triggers a second job where OpenTofu applies the changes to the cloud.

Common failure modes and how to scope roles

Many teams give their GitHub runner a single admin role for both plan and apply jobs. This is a big risk because anyone who opens a pull request can trigger a plan job. A bad actor can change the code to steal keys or delete cloud resources during a plan.

Shared service accounts also make it hard to see who ran what change. When ten repos use the same cloud role, your cloud logs show one identity for all actions. You lose track of which team or repo broke a live database.

GitHub Actions Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix this by splitting your roles into two distinct levels. Give pull request jobs a read-only role so OpenTofu can only check state and make plans. Give the main branch job a write role that only runs after a human approves the merge.

You should also lock down network paths between your runners and your cloud state backend. Put your runners in a private network when they need to reach private clusters or databases. Scope each repo to its own state file so one bad run cannot corrupt another app.

Keeping state files and logs clean

OpenTofu state files and plan logs often hold raw passwords, API keys, and database URLs. When GitHub posts a plan output to a pull request comment, those secrets can leak to anyone with repo read rights. Even private repos often have hundreds of readers across a company.

Teams should restrict who can read workflow logs and pull request comments on stack repos. You should also encrypt remote state storage at rest and limit state read permissions to specific runner roles. When you need to mask sensitive data in outputs, rewrite matched fields like emails, phone numbers, card numbers, or national IDs.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How do I stop pull requests from making live cloud changes?

Bind your cloud write role only to workflows that run on your protected main branch. Use a separate read-only role for all pull request plan jobs.

Where should OpenTofu store its state file when running in GitHub?

Store the state file in a remote cloud bucket with state locking turned on. Never commit the state file back into your GitHub repo.

Why should I avoid static cloud keys in GitHub secrets?

Static keys do not expire on their own and are hard to rotate across many repos. Using OpenID Connect gives each workflow run a short-lived token tied to that exact repo.

The query runs. The emails stay hidden.