Challenge 5: Cloud SQL

Previous Challenge Next Challenge

Introduction

We know, Firestore is a great product with an incredibly high service level agreement (SLA), but it’s a proprietary database, and it’s a document store.

When it comes to querying data, relational databases are hard to beat. Who doesn’t love SQL? Let’s take a look at connecting Cloud Run to Cloud SQL: a fully-managed product that provides MySQL, PostgreSQL and SQL Server.

Cloud SQL

Description

We’ve already deployed a Cloud SQL instance for you. If you browse to /sql, you’ll see that things are not working properly yet. You need to make sure that Cloud Run can connect to it. Pass the database name (database), database user name (app) and the database user password (my-precious) as environment variables in plain text (don’t worry we’ll fix that later) to the Cloud Run instance.

Note
The Compute Engine default service account has been assigned the right roles to access the SQL database. If you choose any other service account for your Cloud Run app, you’ll have to make sure that it has the right permissions.

Success Criteria

  • Cloud Run is configured to connect to the Cloud SQL instance
  • Database details are passed as environment variables to the Cloud Run instance
  • The endpoint /sql returns OK
  • The tests in sql.test.js are all passing
  • No code change is needed for this challenge

Learning Resources

Tips

  • You can find the instance name of the Cloud SQL instance on the Cloud SQL instances page in the Google Cloud console

Previous Challenge Next Challenge