Terraform MySQL Provider
The terraform mysql provider lets your team manage database schemas, users, and permissions as code. You define your desired database state in files, and the tool applies those changes. Most engineering teams use this setup to create app roles and user accounts. Still, teams often grant broad permissions so they do not block urgent developer work. Those wide roles stay active long after the initial task ends. How the terraform mysql provider works This tool acts as a bridge between your code
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.
The terraform mysql provider lets your team manage database schemas, users, and permissions as code. You define your desired database state in files, and the tool applies those changes. Most engineering teams use this setup to create app roles and user accounts. Still, teams often grant broad permissions so they do not block urgent developer work. Those wide roles stay active long after the initial task ends.
How the terraform mysql provider works
This tool acts as a bridge between your code files and your database server. First, an engineer writes definitions for databases, user accounts, and role grants. Next, the deployment tool reads those definitions and compares them to the current state. If a database or user does not exist yet, the tool creates it. If a permission grant has changed in the code, the tool updates the server.
To make these changes, the tool must log in with a root account. It sends standard SQL statements over the network to the target server. Teams store the current state of these database objects in a shared state file. When someone updates a role in code, the pipeline runs a check first. After a peer reviews the plan, the pipeline applies the new grant to MySQL. This workflow keeps staging and production schemas in sync across every cloud region. It also gives teams a clear Git history of who requested each schema change.
Managing users and grants in code
Manual user creation leads to drift across different database servers over time. One engineer might grant read permissions on a single table in staging. Another engineer might grant full write rights across the entire production server. Defining users and grants in code stops this drift from happening. Every user account, host rule, and table grant lives in version control. When an employee leaves the team, removing their block from code revokes their user.
Teams also use this setup to rotate static passwords for apps and services. You can pass secrets from a secret store into the run at deploy time. Yet managing secrets in state files introduces its own security risk. Anyone who can read the state file can read the raw database passwords. Even if you encrypt the state store, the static credentials remain valid on MySQL. Engineers still copy those credentials into local database tools to run manual queries.
Terraform Provider for Security + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where static database setup falls short
Provisioning users through code solves how accounts get created on the server. It decides who can log in and which schemas they can touch. Still, it cannot control what individual SQL statements do during a live session. Once a developer logs in with a provisioned user, the database trusts every command. A user with read access can dump a whole table of customer emails. A user with write access can drop rows or alter sensitive records by mistake.
Static grants also keeps the session active twenty-four hours a day once applied. Teams rarely run a full code deployment just to grant five minutes of access. Instead, they create shared admin roles and hand out the login details during incidents. Standard MySQL logs only show that the shared role ran a query. They do not link that query back to a specific person on your team. Static code also cannot rewrite sensitive fields like phone numbers or card numbers in results.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL. It runs next to MySQL, RDS, or Aurora and reads the MySQL wire protocol.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails. When a rule refuses a query, MySQL returns a native error packet with your message. On the response path, hoop.dev data masking rewrites string values in returned rows that match your rules. Every query and decision is logged per resource. See the MIT-licensed project on GitHub.
Frequently asked questions
Does the terraform mysql provider manage cloud database instances?
No, it only manages objects inside an existing MySQL server, like users and schemas. You use your cloud provider plugin to spin up the actual server hardware first.
How does the tool authenticate to the MySQL server?
It logs in using an admin username and password or a cloud token. This account needs high permissions so it can create new databases and grant roles.
Why are passwords visible in the Terraform state file?
The tool records every input attribute in its state file to track future changes. You must encrypt your remote state storage and restrict who can read those files.
Related guides
In this post