mirror of
https://github.com/ryboe/private-ip-cloud-sql-db.git
synced 2025-12-19 18:14:59 -05:00
20a7c64c9a7a3c8ef41a7fdcb0f65503988364b9
* Upgrade db from Postgres 11 -> 13 * Upgrade tfe and google provider plugins * Remove google-beta provider since it's no longer needed * Add .terraform-version file to support tfenv * Add .vscode/ settings to play nice with VSCode * Clean up .gitignore
Cloud SQL DB with a Private IP
This repo demonstrates how to create a Cloud SQL DB with a private IP address only, and connect to it with Cloud SQL Proxy. The full explanation of how this works can be found in this blog post.
Terraform v0.14.0 or higher is required.
Deploy the db and Cloud SQL Proxy
gcloud services enable \
cloudresourcemanager.googleapis.com \
compute.googleapis.com \
iam.googleapis.com \
oslogin.googleapis.com \
servicenetworking.googleapis.com \
sqladmin.googleapis.com
terraform init
terraform apply
Upload your public SSH key to Google's OS Login service
gcloud compute os-login ssh-keys add --key-file=~/.ssh/id_rsa.pub --ttl=365d
Connect to the private db through Cloud SQL Proxy
# get your SSH username
gcloud compute os-login describe-profile | grep username
# psql into your private db
ssh -t <username>@<proxy-ip-address> docker run --rm --network=host -it postgres:13-alpine psql -U postgres -h localhost
Languages
HCL
87.1%
Smarty
12.9%