terraform apply, and Terraform calls the relevant APIs to provision and manage your infrastructure. The PowerSync Terraform provider brings PowerSync Cloud into that workflow.
Use it to:
- Provision PowerSync in the same
terraform applythat creates your database and other cloud resources. - Define dev, staging, and production environments once in version-controlled config rather than configuring each manually in the dashboard.
- Review changes to sync configuration, replication connections, and authentication settings as Terraform plan diffs in pull requests.
Prerequisites
- Terraform 1.5 or later
- A PowerSync Cloud account
- A source database. The examples in this guide use Postgres via Supabase. If your database is also managed by Terraform, you can reference it in the same configuration.
Get a Personal Access Token
The provider authenticates using a personal access token. In the dashboard, go to Account → Access Tokens and create a new token. Treat it like a password. It grants account access. Set it as an environment variable before running any Terraform commands:Find Your Organization ID
Your organization ID appears in the dashboard URL. When you are on the organization home page, the URL contains a hex segment like/orgs/64b3f8e1a2c4d5e6f7080912/. That segment is your organization ID.
Configure the Provider
Create a new directory and amain.tf file. Start with the provider declaration:
Create a Project
Add a data source to look up your organization, then a resource to create a project:data "powersync_organization" block reads your existing organization. Organizations are created when you sign up and are not managed as Terraform resources. The powersync_project resource creates a new project under it. Supported regions are eu, us, jp, au, and br.
Create an Instance
Add thepowersync_instance resource, which wires together a replication connection, client authentication, and your sync configuration:
replication_password is a Terraform variable. Pass its value via the environment so it never appears in plain text in your config or state files.
The sync_config_content field takes a Sync Streams configuration as a YAML string. For larger configs, use file("${path.module}/sync-config.yaml") to load the configuration from a separate file. See the Sync Streams documentation for the full configuration reference.
Apply
Set the replication password, then run:terraform plan shows you exactly what Terraform will create before you commit to it. terraform apply creates the project and instance, then deploys it. When it completes, the instance is live. Run terraform show to see the full resource state including the instance URL.
Managing Changes
To update your PowerSync instance, edit any value in your config and re-runterraform plan then terraform apply. Every change triggers a full redeploy. The instance ID and URL remain the same.
Tear Down
force_destroy = true on powersync_project to override this check.
Next Steps
- Full resource and data source reference on the Terraform Registry
- Supabase integration guide for Supabase-specific setup: creating the
powersync_role, configuring publications, and JWT authentication modes - Sync Streams overview for writing the
sync_config_content