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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use drone and opentofu together to automate cloud changes from code commits. Drone runs each pipeline step in a fresh container while OpenTofu applies the state changes. This pairing turns manual server work into a repeatable, reviewed code workflow. Every push triggers a plan, and every merge applies the approved changes. How drone and opentofu share roles and data Drone reads a pipeline file from your code repo when a developer pushes changes. It starts a clean container image that h

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 drone and opentofu together to automate cloud changes from code commits. Drone runs each pipeline step in a fresh container while OpenTofu applies the state changes.

This pairing turns manual server work into a repeatable, reviewed code workflow. Every push triggers a plan, and every merge applies the approved changes.

How drone and opentofu share roles and data

Drone reads a pipeline file from your code repo when a developer pushes changes. It starts a clean container image that holds the OpenTofu binary.

The Drone runner passes cloud keys or workload tokens into that container environment. OpenTofu reads those keys to log in to your cloud provider and state storage.

First, the pipeline runs an init step to pull providers and state data. Next, a plan step checks what cloud resources need to change.

Teams often send this plan output back to the pull request for review. Once a reviewer approves and merges the code, Drone starts the apply step.

Data flows from the git repo into the Drone runner and out to cloud APIs. State files must live in remote storage because Drone wipes the container after each run.

Common failure modes and how to scope permissions

Many teams start by putting one admin cloud key into Drone secrets. This shared service account creates a big security risk across all repos.

If any branch can trigger an apply step, a bad commit can wipe production. Broad tokens also make it hard to see which person caused a cloud change.

Unlogged queries to state storage can leak sensitive values stored inside the state file. State files often hold plain text database keys, phone numbers, or emails.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Two builds running at the same time can also corrupt your state file. You must turn on state locking in your remote backend to stop concurrent writes.

To fix permission sprawl, give each repo and branch its own scoped cloud role. Pull requests should only get read keys to run a safe plan check.

Only the main branch should get write keys to run the apply step. Use short-lived identity tokens instead of static keys stored in Drone secrets.

Lock down network paths so only your build runners can reach private cloud APIs. Keep your production state files in a separate bucket from staging state files.

Managing state and drift across pipeline runs

Containers do not keep local files after a pipeline job ends. You must set up a remote backend before you run any other step.

Remote storage keeps your state safe and lets team members share one source of truth. It also holds the lock record while a build is active.

If a Drone job crashes mid-run, the state lock might stay stuck. An engineer must check the cloud console to verify the job stopped before clearing locks.

You can also schedule daily Drone jobs to run a plan check without changes. This scheduled run alerts your team when someone edits cloud settings by hand.

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

How do we stop two Drone builds from breaking OpenTofu state?

Store your state in remote storage that supports state locking. You should also set concurrency limits in Drone so only one build runs per branch.

Should pull requests have write permissions for cloud resources?

No, pull requests should only run plan checks using a read-only role. Reserve write roles for merges to your main branch after code review.

Where should OpenTofu state files live when using Drone?

State files must live in remote object storage with encryption and locking turned on. Never save state inside the Drone container or commit it to git.

The query runs. The emails stay hidden.