Skip to content
Latchkey

gcloud sql instances create: Provision Cloud SQL

gcloud sql instances create provisions a managed Cloud SQL instance of the engine and size you choose.

Integration tests that need a real database can stand up a throwaway Cloud SQL instance. The engine version and machine tier are the main choices.

What it does

gcloud sql instances create provisions a Cloud SQL instance for Postgres, MySQL, or SQL Server in the chosen region, with the database version and machine tier you specify. Provisioning takes several minutes.

Common usage

Terminal
gcloud sql instances create test-db \
  --database-version=POSTGRES_15 \
  --tier=db-f1-micro --region=us-central1
# create a database and user after the instance is up
gcloud sql databases create app --instance=test-db
gcloud sql users create app --instance=test-db --password="$DB_PASS"

Flags

FlagWhat it does
--database-version <ver>Engine and version, e.g. POSTGRES_15
--tier <tier>Machine tier, e.g. db-f1-micro or db-custom-2-7680
--region <region>Region to create the instance in
--edition ENTERPRISE|ENTERPRISE_PLUSCloud SQL edition
--no-backupSkip automated backups (cheaper for throwaway DBs)

In CI

Authenticate keylessly with Workload Identity Federation; the identity needs roles/cloudsql.admin to create instances. Use a small --tier and --no-backup for ephemeral test databases, and delete the instance in a cleanup step so it stops billing.

Common errors in CI

"The Cloud SQL instance already exists" means the name is taken or recently deleted; instance names are reserved for about a week after deletion. "Quota exceeded" means not enough instances in the region. "Cloud SQL Admin API has not been used in project ..." means enable sqladmin.googleapis.com.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →