This Terraform template creates a Compute Engine instance pre-configured with pgcopydb, the tool PlanetScale uses to migrate your PostgreSQL data. The instance runs Ubuntu 24.04 and pulls the latest PlanetScale migration helper scripts at boot.
- A Compute Engine instance with pgcopydb and PostgreSQL client tools installed
- A persistent disk for migration working data
- A firewall rule for SSH access via IAP tunnel
- A startup script that installs all required tools
- Migration helper scripts from
github.com/planetscale/migration-scriptsin/home/ubuntu/
- Terraform installed (v1.0+)
- A GCP project with a VPC and subnet
gcloudCLI authenticated
-
Save both files (
pgcopydb-migration-instance.tfandstartup-script.sh) in the same directory -
Deploy (restricting SSH to your IP is recommended — get it from icanhazip.com):
terraform init terraform apply \ -var="project_id=YOUR_PROJECT" \ -var="vpc_name=YOUR_VPC" \ -var="subnet_name=YOUR_SUBNET" \ -var="your_public_ip=$(curl -s icanhazip.com)"
-
Connect via IAP tunnel:
gcloud compute ssh $(terraform output -raw instance_name) \ --zone=$(terraform output -raw zone) \ --project=YOUR_PROJECT \ --tunnel-through-iap
Or via the GCP Console (browser-based SSH — open the instance in Compute Engine and click SSH).
terraform destroy \
-var="project_id=YOUR_PROJECT" \
-var="vpc_name=YOUR_VPC" \
-var="subnet_name=YOUR_SUBNET" \
-var="your_public_ip=$(curl -s icanhazip.com)"Visit PlanetScale documentation for more information.