The Simplest Way to Make AWS RDS and OpenTofu Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use aws rds and opentofu to build and update cloud databases from code. This pairing lets engineers define database sizes, networks, and rules in text files. When a team updates the text files, the tool talks to the cloud API. It creates new database instances, changes storage limits, and sets up backup rules. Engineers do not need to click through cloud menus by hand. Every change goes through peer review before it touches a live database. How aws rds and opentofu share roles and data

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 aws rds and opentofu to build and update cloud databases from code. This pairing lets engineers define database sizes, networks, and rules in text files.

When a team updates the text files, the tool talks to the cloud API. It creates new database instances, changes storage limits, and sets up backup rules. Engineers do not need to click through cloud menus by hand. Every change goes through peer review before it touches a live database.

How aws rds and opentofu share roles and data

The workflow starts when an engineer or pipeline runs a plan or apply step. The tool needs cloud rights to talk to the database service API. Teams give the tool a cloud role with specific create and update rights. The tool sends requests to the cloud API using that temporary role.

The cloud service then builds the database inside a private network. It returns host names, ports, and resource IDs back to the tool. The tool saves all of these details inside a state file. Teams store this state file in a remote cloud bucket with strict locks.

Inside the database, a separate login flow happens for users and apps. The cloud API builds the box, while SQL engines check user logins. Some teams also use the tool to set up database schemas and roles. To do this, the tool must reach the database port over the network. It logs in as a master user to create smaller app roles.

Common traps with shared keys and state files

Many teams fall into a big trap with initial database passwords. If you put a plain password in your code, it lands in the state file. Anyone who can read the state file can now see the master password. A better path is to let the cloud service manage the master secret. You can also create random passwords that rotate right after creation.

Shared cloud keys create another huge risk for engineering teams. If five engineers share one admin key to run updates, audit logs break. You cannot tell who changed a database rule or deleted a table. Instead, each engineer and pipeline should use a separate, named role. Give pipelines write rights, and give most humans read-only plan rights.

AWS IAM Policies + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Network paths also cause major headaches during database updates. Databases should stay in private subnets with no public IP addresses. When a pipeline runs from the outside internet, it cannot reach the database port. Teams often open wide network rules just to let the pipeline finish. This bad habit exposes the database to far too many machines. Instead, run your update jobs inside the same private network as the database. Scope security groups so only that runner can reach the database port.

Scoping database roles and daily operations

Once the database is up, humans still need to run SQL checks. Do not use the master user from your code for daily queries. Create separate SQL roles for read-only checks, app writes, and schema changes. Map each team member to their own identity so every query has an owner.

Keep your code changes and your data queries on separate tracks. Use your code tool for box size, disk space, and network rules. Use strict, logged SQL sessions when engineers need to read or fix live data. When sensitive columns like emails, phone numbers, or card numbers exist, masking rewrites matched fields in results.

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 keep database passwords out of the state file?

Tell the cloud database service to manage the master user password in its own secret store. This keeps raw password strings out of your code and state files.

Should we manage database users and tables with the same state file?

No, split cloud box setup and inside-the-database setup into two separate states. This stops a minor network timeout from blocking all of your cloud updates.

How can we stop accidental database deletes during a run?

Turn on deletion protection on the database resource and add lifecycle rules in your code. Both checks will block a bad plan from dropping a live instance.

The query runs. The emails stay hidden.