Using Terraform to provision Cloud Run services
In our example, we will deploy two Cloud Run services. The first one is a simple Hello
example. The second service accesses the Redis database. We will include the code for both services for your reference so that you can build your own container images. The sample code uses container images from a public container repository.
We want the Cloud Run service to be publicly accessible – that is, not require any authentication. For enhanced security, we will allow the Cloud Run services to ingress only via the load balancer and use the service account we provisioned in the foundation layer.
First, let’s have a look at how we deploy the hello
service. First, we must provision the Cloud Run service using the google_cloud_run_service
resource. We need to specify the container source and the service account name. To restrict the ingress restriction, we need to add an annotation, as follows:
chap06/main/cloudrun.tf
resource...