Giter VIP home page Giter VIP logo

gcp-sql-auto-authorize-instance's Introduction

gcp-sql-auto-authorize-instance

What is this?

This script is used to automatically authorize a GCP Auto-Scale Instance Group to a Google Cloud SQL database. The script does not rely on the gcloud command, allowing it be be associated with Google's Container-Optimized OS. This solution was inspired by this ServerFault post.

Why this solution?

Using the Cloud SQL Proxy seems to be the way GCP is pushing everyone to overcome this hurdle. However, keep in mind that once you go down that path, you'll be coupled to GCP. Your application will have to have direct knowledge of a GCP-specific component to be able to communicate with the DB -- something that is only necessary for the application to run in GCP, and nowhere else.

Due to this undesirable consequence, I have implemented this script to avoid coupling your application to GCP. The advantage of this approach is that it isolates the logic necessary to communicate with the SQL instance, and associates it with GCP-specific configurations instead of the application itself.

The script will allow an auto-scaling instance group to automatically gain authorization to a SQL instance. It runs inside GCP's Container-Optimized OS, which does not have gcloud installed.

How to use it?

This script is meant to be used as the Startup Script in the configuration for a VM Instance Template.

To install this script:

  1. Enable a Sql Admin API for the project containing your instance
  2. In the script, replace <your project id> with your project id, and <your db id> with your DB id.
  3. Go to cloud.google.com -> Compute Engine -> Instance Templates.
  4. Create a new Instance Template, or copy an existing one.
  5. Click on Management, security, disks, networking, sole tenancy to expand the desired configuration fields.
  6. In the Automation section, copy+paste the script you edited in (1) into the Startup script textbox.
  7. Click Create, and you're done!

How does it work?

  1. Gain access to call the SQL API.
  2. Get the IPs already authorized to the SQL database.
  3. If the $EXTERNAL_IP of the new instance already exists in the authorized IPs, then return.
  4. Otherwise, append the $EXTERNAL_IP to the authorized IPs, and patch the SQL database settings.

gcp-sql-auto-authorize-instance's People

Contributors

despossivel avatar safris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gcp-sql-auto-authorize-instance's Issues

Where does this run?

Hi - I'm trying to use your script with a GAE application, and can't get it to run successfully. (I believe I have the script running now; but it doesn't seem to manage to assign IP addresses to the DB whitelist.)

Please could you tell me how you use the script in a GCP app deploy cycle? Where does the script reside, and what invokes it?

Many thanks

Nic Ford

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.