Add Cloud Run example
ADD
gcp-py-cloudrun-cloudsql/.gitignore
+venv/

ADD
gcp-py-cloudrun-cloudsql/Pulumi.yaml
+name: gcp-py-cloudrun-cloudsql
+runtime:
+ name: python
+ options:
+ virtualenv: venv
+description: Basic example of a Google Cloud Run and Google Cloud SQL deployment
+template:
+ config:
+ gcp:project:
+ description: The Google Cloud project to deploy into
+ gcp:zone:
+ description: The Google Cloud zone
+ db-name:
+ description: Name and Username of Cloud SQL database
+ db-password:
+ description: Password used in Cloud SQL database
+ secret: true

ADD
gcp-py-cloudrun-cloudsql/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Deploy Cloud Run instance connected to Cloud SQL
+
+Example of starting a Cloud Run deployment with Cloud SQL instance
+
+## Running the App
+
+1. Create a Python virtualenv, activate it, and install dependencies:
+
+ This installs the dependent packages [needed](https://www.pulumi.com/docs/intro/concepts/how-pulumi-works/) for our Pulumi program.
+
+ ```bash
+ $ python3 -m venv venv
+ $ source venv/bin/activate
+ $ pip3 install -r requirements.txt
+ ```
+
+1. Create a new stack:
+
+ ```
+ $ pulumi stack init dev
+ ```
+
+1. Configure the project:
+
+ ```
+ $ pulumi config set gcp:project YOURGOOGLECLOUDPROJECT
+ $ pulumi config set gcp:zone europe-west1
+ $ pulumi config set db-name project-db
+ $ pulumi config set --secret db-password SuuperSecret12345!
+ ```
+
+1. Preview and deploy changes:
+ ```
+ $ pulumi up
+ ```
+
+1. Curl the Cloud Run:
+
+ ```
+ $ curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" $(pulumi stack output cloud_run_url)
+ ```
+
+1. Access the database:
+
+ ```
+ $ gcloud sql connect $(pulumi stack output cloud_sql_instance_name) -u $(pulumi config get db-name) --project $(pulumi config get gcp:project)
+ ```
+
+1. Cleanup
+
+ ```
+ $ pulumi destroy
+ $ pulumi stack rm
+ ```
\ No newline at end of file

ADD
gcp-py-cloudrun-cloudsql/__main__.py
+import pulumi
+import pulumi_gcp
+from pulumi import Output, Config
+from pulumi_gcp.cloudrun import (
+ ServiceTemplateMetadataArgs,
+ ServiceTemplateSpecContainerEnvArgs,
+)
+
+config = Config()
+
+cloud_sql_instance = pulumi_gcp.sql.DatabaseInstance(
+ "my-cloud-sql-instance",
+ database_version="POSTGRES_12",
+ deletion_protection=False,
+ settings=pulumi_gcp.sql.DatabaseInstanceSettingsArgs(tier="db-f1-micro"),
+)
+
+database = pulumi_gcp.sql.Database(
+ "database", instance=cloud_sql_instance.name, name=config.require("db-name")
+)
+
+users = pulumi_gcp.sql.User(
+ "users",
+ name=config.require("db-name"),
+ instance=cloud_sql_instance.name,
+ password=config.require_secret("db-password"),
+)
+
+sql_instance_url = Output.concat(
+ "postgres://",
+ config.require("db-name"),
+ ":",
+ config.require_secret("db-password"),
+ "@/",
+ config.require("db-name"),
+ "?host=/cloudsql/",
+ cloud_sql_instance.connection_name,
+)
+
+cloud_run = pulumi_gcp.cloudrun.Service(
+ "default-service",
+ location=Config("gcp").require("zone"),
+ template=pulumi_gcp.cloudrun.ServiceTemplateArgs(
+ metadata=ServiceTemplateMetadataArgs(
+ annotations={
+ "run.googleapis.com/cloudsql-instances": cloud_sql_instance.connection_name
+ }
+ ),
+ spec=pulumi_gcp.cloudrun.ServiceTemplateSpecArgs(
+ containers=[
+ pulumi_gcp.cloudrun.ServiceTemplateSpecContainerArgs(
+ image="gcr.io/cloudrun/hello",
+ envs=[
+ ServiceTemplateSpecContainerEnvArgs(
+ name="DATABASE_URL",
+ value=sql_instance_url,
+ )
+ ],
+ )
+ ],
+ ),
+ ),
+ traffics=[
+ pulumi_gcp.cloudrun.ServiceTrafficArgs(
+ latest_revision=True,
+ percent=100,
+ )
+ ],
+)
+
+pulumi.export("cloud_sql_instance_name", cloud_sql_instance.name)
+pulumi.export("cloud_run_url", cloud_run.statuses[0].url)

ADD
gcp-py-cloudrun-cloudsql/requirements.txt
+pulumi==2.17.0
+pulumi-gcp==4.6.0

Add Cloud Run example