Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryboe/private-ip-cloud-sql-db
An example set of terraform files for deploying a Cloud SQL DB with a private IP address only
https://github.com/ryboe/private-ip-cloud-sql-db
Last synced: 3 months ago
JSON representation
An example set of terraform files for deploying a Cloud SQL DB with a private IP address only
- Host: GitHub
- URL: https://github.com/ryboe/private-ip-cloud-sql-db
- Owner: ryboe
- License: mit
- Created: 2020-04-17T03:06:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-15T20:27:42.000Z (over 1 year ago)
- Last Synced: 2024-04-22T22:21:37.676Z (7 months ago)
- Language: HCL
- Homepage:
- Size: 28.3 KB
- Stars: 34
- Watchers: 3
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - ryboe/private-ip-cloud-sql-db - An example set of terraform files for deploying a Cloud SQL DB with a private IP address only (HCL)
README
# 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](https://cloud.google.com/sql/docs/postgres/sql-proxy). The full explanation of how this works can be found in [this blog post](https://medium.com/@ryanboehning/how-to-deploy-a-cloud-sql-db-with-a-private-ip-only-using-terraform-e184b08eca64).Terraform v1.0.0 or higher is required.
## How To Use
1. Set the name of your Terraform Cloud organization in `backend.tf`.
2. Deploy the db and Cloud SQL Proxy
```bash
gcloud services enable \
cloudresourcemanager.googleapis.com \
compute.googleapis.com \
iam.googleapis.com \
oslogin.googleapis.com \
servicenetworking.googleapis.com \
sqladmin.googleapis.comterraform init
terraform apply
```3. Upload your public SSH key to Google's OS Login service
```bash
gcloud compute os-login ssh-keys add --key-file=~/.ssh/id_rsa.pub --ttl=365d
```4. Connect to the private db through Cloud SQL Proxy
```bash
# get your SSH username
gcloud compute os-login describe-profile | grep username# get the public IP of the instance running Cloud SQL Proxy
CLOUD_SQL_PROXY_IP=$(terraform output proxy_ip)# psql into your private db
ssh -t @$CLOUD_SQL_PROXY_IP docker run --rm --network=host -it postgres:14-alpine psql -U postgres -h localhost
```