Conceptual model
The PlanetScale Terraform provider is organized around a clear distinction between Vitess and Postgres resources and is focused on long-lived infrastructure objects.- There are separate resources for each database kind—Vitess or Postgres.
- The provider maps cleanly onto PlanetScale’s public API while exposing Terraform-friendly fields and lifecycle behavior.
- Applying a
planetscale_postgres_branchorplanetscale_vitess_branchcreates the parent database if it does not already exist. - Destroying the last branch in a database also destroys the database. See Deletion protection for safeguards.
Credential models
Vitess and Postgres use different terminology for database credentials:| Database Type | Resource | How permissions work |
|---|---|---|
| Vitess | planetscale_vitess_branch_password | Set the role attribute to reader, writer, readwriter, or admin |
| Postgres | planetscale_postgres_branch_role | Use inherited_roles to inherit from built-in Postgres roles like pg_read_all_data or pg_write_all_data |
Quick start
This complete example creates a Postgres branch with application credentials:Available resources
The provider offers resources for the most common automation scenarios:planetscale_postgres_branchplanetscale_postgres_branch_backupplanetscale_postgres_branch_roleplanetscale_postgres_backup_policyplanetscale_vitess_branchplanetscale_vitess_branch_backupplanetscale_vitess_branch_passwordplanetscale_vitess_backup_policy
Data sources
The provider also offers data sources for reading existing resources:planetscale_databasesplanetscale_database_postgresplanetscale_database_vitessplanetscale_organizationplanetscale_organizationsplanetscale_postgres_backup_policiesplanetscale_postgres_backup_policyplanetscale_postgres_branchplanetscale_postgres_branch_backupplanetscale_postgres_branch_backupsplanetscale_postgres_branch_roleplanetscale_postgres_branch_rolesplanetscale_vitess_backup_policiesplanetscale_vitess_backup_policyplanetscale_vitess_branchplanetscale_vitess_branch_backupplanetscale_vitess_branch_backupsplanetscale_vitess_branch_passwordplanetscale_vitess_branch_passwords
Data source behavior
| Data Source | Required Inputs | Notes |
|---|---|---|
planetscale_databases | organization | Lists all databases. Optional q parameter for filtering by name. |
planetscale_database_postgres | organization | Returns Postgres database info. Does not accept a database name filter. |
planetscale_database_vitess | organization | Returns Vitess database info. Does not accept a database name filter. |
planetscale_postgres_backup_policies | organization, database | Lists Postgres backup policies for a database. |
planetscale_postgres_backup_policy | organization, database, id | Fetches a specific Postgres backup policy by ID. |
planetscale_postgres_branch | organization, database | Returns the default branch. Does not accept a branch name parameter. |
planetscale_postgres_branch_backups | organization, database, branch | Lists Postgres backups for a branch. Supports filters like state, from, to, and policy. |
planetscale_postgres_branch_backup | organization, database, branch, id | Fetches a specific Postgres backup by ID. |
planetscale_postgres_branch_roles | organization, database, branch | Lists all roles on a branch. |
planetscale_postgres_branch_role | organization, database, branch, id | Fetches a specific role by ID. Useful for importing existing roles. |
planetscale_vitess_backup_policies | organization, database | Lists Vitess backup policies for a database. |
planetscale_vitess_backup_policy | organization, database, id | Fetches a specific Vitess backup policy by ID. |
planetscale_vitess_branch | organization, database | Returns the default branch. Does not accept a branch name parameter. |
planetscale_vitess_branch_backups | organization, database, branch | Lists Vitess backups for a branch. Supports filters like state, from, to, and policy. |
planetscale_vitess_branch_backup | organization, database, branch, id | Fetches a specific Vitess backup by ID. |
planetscale_vitess_branch_passwords | organization, database, branch | Lists all passwords on a branch. |
planetscale_vitess_branch_password | organization, database, branch, id | Fetches a specific password by ID. |
planetscale_organization | organization | Returns organization details. |
planetscale_organizations | (none) | Lists all accessible organizations. |
Provider configuration
The provider supports authentication using service tokens. Example configuration:| Provider Attribute | Environment Variable | Description |
|---|---|---|
service_token_id | PLANETSCALE_SERVICE_TOKEN_ID | PlanetScale Service Token ID |
service_token | PLANETSCALE_SERVICE_TOKEN | PlanetScale Service Token |
server_url | PLANETSCALE_SERVER_URL | Optional server URL override |
Example usage
Vitess branch and password
Postgres branch and role
Backups and backup policies
Use backup policy resources to define automatic backup schedules. Use branch backup resources to create managed backups. Both Vitess and Postgres support backup policies and branch backups. Postgres branch backups also support theemergency option.
planetscale_vitess_backup_policy and planetscale_vitess_branch_backup with the same scheduling and retention fields.
Postgres parameters and extensions
Postgres branches support aparameters map for cluster settings, PgBouncer settings, Patroni settings, and supported extension settings. Parameters are nested by namespace: pgconf, pgbouncer, and patroni.
Retrieving connection details
After creating a role or password, use Terraform outputs to retrieve connection information:Postgres
Vitess
The
password (Postgres) and plain_text (Vitess) fields are only available after the initial terraform apply. They are marked as sensitive and stored in Terraform state.Practical examples
Development branch workflow
Create a development branch forked from your main branch. Optionally specify a larger cluster size if you need more resources than the default:Read-only role for reporting
Create a role with read-only access for analytics and reporting:Short-lived CI/CD credentials
Create credentials that automatically expire for CI/CD pipelines:Configuration reference
| Attribute | Valid Values |
|---|---|
cluster_size | Use the Clusters API to get the list of available cluster sizes |
region | See available regions |
major_version (Postgres) | 17, 18 |
parameters (Postgres) | Map of string values nested under pgconf, pgbouncer, or patroni |
retention_unit | hour, day, week, month, year |
frequency_unit | hour, day, week, month |
target (backup policies) | production, development |
role (Vitess) | reader, writer, readwriter, admin |
inherited_roles (Postgres) | pg_read_all_data, pg_write_all_data, or any custom role |
Deletion protection
Branch deletion is one of the most sensitive operations in infrastructure automation. To reduce risk, use Terraform’slifecycle block to prevent accidental destruction of critical resources:
apply, particularly for changes that delete or recreate branches.
Upgrading from v0.x to v1.x
The original PlanetScale Terraform provider was not officially supported for production use and is no longer maintained. Because the new v1 provider is a breaking rewrite, migration from v0.x to v1.x is a one-time, manual transition. Projects using the v0 provider will continue to work as normal, but this version will not receive further updates.- Pin v0.x in existing workloads
- Ensure all existing Terraform projects using the PlanetScale provider are pinned to
~> 0.6.1(or a specific v0.x version) to avoid unintentional upgrades.
- Ensure all existing Terraform projects using the PlanetScale provider are pinned to
- Create a new Terraform project for v1.x
- Create a separate directory with a new configuration using the v1 provider.
- Use the v1 resource types for Vitess/Postgres branches, roles, passwords, and other supported resources.
- Run
terraform initto download the v1 provider and initialize your working directory. This creates a new, independent state file.
- Import existing resources into v1.x state
- For each resource that you want Terraform to manage going forward, run
terraform importfor the corresponding v1 resource. - Expect import to use IDs that align with the v1 API design (for example, IDs rather than purely name-based identifiers).
- For each resource that you want Terraform to manage going forward, run
- Cut over automation
- After resources are imported and
terraform planshows no unexpected changes, switch your automation (CI pipelines, etc.) to apply the v1 project.
- After resources are imported and
- Sunset v0.x usage
- Once you have validated v1.x in production, retire the v0.x configurations and keep them only for historical reference, if needed.

