Giter VIP home page Giter VIP logo

postgrest-cloud-run's Introduction

Expose your Postgres database on Cloud SQL easily with Cloud Run

The PostgREST project provides a CRUD API on top of your postgres database.
What better way to explore your data than with an OpenAPI running on Cloud Run?

Overview

Thanks to Cloud Run easy integration with Cloud SQL and Secret Manager it's very easy to connect all we need!

Your data in Cloud SQL
↕️
VPC Connector
↕️
SQL Connection
↕️
Cloud Run service


Content of this repo 🕵🏻

This repo serves as a demo, it will:

  • Create a Cloud SQL instance with Postgres in a private VPC.
  • Set the postgres password and store it in Secret Manager
  • Initialize a Cloud Run Service, with a VPC Connector, a SQL Connection to the SQL instance, and mounting the password from Secret
  • Finally, output the Service Endpoint and optional gcloud commands to populate the database

/!\ Permission: the resulting Cloud Run service is available publicly for ease of access


Exemple of deployed interface ⤵️ swagger preview

Exemple generated openapi spec: openapi.json


.
├── cloud_run
│   ├── cloud_run.tf
│   ├── outputs.tf
│   └── variables.tf
│
├── cloud_sql
│   ├── outputs.tf
│   ├── postgres.tf
│   └── variables.tf
│
├── secret_manager
│   ├── outputs.tf
│   ├── secret_manager.tf
│   └── variables.tf
│
└── main.tf
├── terraform.tfvars
└── [backend.tf]

Deploy 🚀

Authenticate first using gcloud's ADC

gcloud auth application-default login

Fill in your own GCP project id in the terraform.tfvars file.
[Optionnaly, uncomment the backend.tf file and fill in your GCS bucket name if you want a remote state.]

Deploy!

tf init
tf plan -var-files=terraform.tfvars -out tfplan

# (the tf apply will start immediately,
#+ you better review the tf plan output first)
tf apply tfplan

Go grab a coffee while Terraform is doing its magic ☕️ ✨

Come back to Terraform outputting gcloud commands to populate the db and the service URL to inspect your data! 🔍 👀

Cleanup 🧹

Set the deletion_protection field in cloud_sql/postgres.tf to false on the SQL Database instance:

  resource "google_sql_database_instance" "postgrest" {
      (...)
      deletion_protection = true -> false
      (...)
  }

Apply the change

tf apply -var-file=terraform.tfvars \
  -target module.postgrest_database.google_sql_database_instance.postgrest

Confirm you want to delete all resources

tf destroy

postgrest-cloud-run's People

Contributors

cyril-sabourault avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jimbrig

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.