Ryan Boehning 20a7c64c9a Update files for Terraform v0.14 (#1)
* 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
2020-12-05 17:47:36 -08:00
2020-04-19 03:40:44 -07:00
2020-12-05 17:47:36 -08:00
2020-04-19 03:40:44 -07:00

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
Description
No description provided
Readme MIT 126 KiB
Languages
HCL 87.1%
Smarty 12.9%