Deploy Cloud Run instance connected to Cloud SQL
Basic example of a Google Cloud Run and Google Cloud SQL deployment
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set gcp-py-cloudrun-cloudsqlcd pulumi-examples/gcp-py-cloudrun-cloudsqlExample of starting a Cloud Run deployment with a Cloud SQL instance.
Prerequisites#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Configure the project:
Terminal window pulumi config set gcp:project YOURGOOGLECLOUDPROJECTpulumi config set gcp:region europe-west1pulumi config set db-name project-dbpulumi config set --secret db-password SuuperSecret12345! -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Preview and deploy changes:
Terminal window pulumi up -
Curl the Cloud Run service:
Terminal window curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" $(pulumi stack output cloud_run_url) -
Access the database:
Terminal window gcloud sql connect $(pulumi stack output cloud_sql_instance_name) -u $(pulumi config get db-name) --project $(pulumi config get gcp:project)
Cleaning up#
Once you’re finished experimenting, destroy your stack and remove it:
pulumi destroypulumi stack rm