Google Cloud Run Service

This page shows how to write Terraform for Cloud Run Service and write them securely.

google_cloud_run_service (Terraform)

The Service in Cloud Run can be configured in Terraform with the resource name google_cloud_run_service. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

secondary.tf#L2
resource "google_cloud_run_service" "run_secondary_1" {
  name = "secondary-1"
  location = "us-central1"

  template {
    spec {
primary.tf#L2
resource "google_cloud_run_service" "run_primary_1" {
  name = "primary-1"
  location = "us-east1"

  template {
    spec {
cloudrun.tf#L1
resource "google_cloud_run_service" "app" {
  name                       = "app"
  location                   = "us-east1"
  autogenerate_revision_name = true
  template {
    spec {
run.tf#L4
resource "google_cloud_run_service" "ingestion_service" {
  name     = var.ingestion_service_name
  location = var.compute_region
  project  = var.project_id

  template {
run.tf#L1
resource "google_cloud_run_service" "cloud-run-test" {
  name     = "cloud-run-test"
  location = var.DEFAULT_REGION

  template {
    spec {

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The location of the cloud run instance. eg us-central1

Name must be unique within a namespace, within a Cloud Run region. Is required when creating resources. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names

  • project optional computed - string
  • status optional computed - list of object

The current status of the Service.

  • conditions - list of object
  • latest_created_revision_name - string
  • latest_ready_revision_name - string
  • observed_generation - number
  • url - string
  • metadata list block

    Annotations is a key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations Note: The Cloud Run API may add additional annotations that were not provided in your config. If terraform plan shows a diff where a server-side annotation is added, you can add it to your config or apply the lifecycle.ignore_changes rule to the metadata.0.annotations field. Cloud Run (fully managed) uses the following annotation keys to configure features on a Service: - 'run.googleapis.com/ingress' sets the ingress settings for the Service. For example, '"run.googleapis.com/ingress" = "all"'.

    A sequence number representing a specific generation of the desired state.

    • labels optional computed - map from string to string

    Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and routes. More info: http://kubernetes.io/docs/user-guide/labels

    In Cloud Run the namespace must be equal to either the project ID or project number.

    An opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed. May be used for optimistic concurrency, change detection, and the watch operation on a resource or set of resources. They may only be valid for a particular resource or set of resources. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#concurrency-control-and-consistency

    SelfLink is a URL representing this object.

    • uid optional computed - string

    UID is a unique id generated by the server on successful creation of a resource and is not allowed to change on PUT operations. More info: http://kubernetes.io/docs/user-guide/identifiers#uids

  • template list block
    • metadata list block

      Annotations is a key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations Note: The Cloud Run API may add additional annotations that were not provided in your config. If terraform plan shows a diff where a server-side annotation is added, you can add it to your config or apply the lifecycle.ignore_changes rule to the metadata.0.annotations field.

      A sequence number representing a specific generation of the desired state.

      • labels optional - map from string to string

      Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and routes. More info: http://kubernetes.io/docs/user-guide/labels

      • name optional computed - string

      Name must be unique within a namespace, within a Cloud Run region. Is required when creating resources. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names

      In Cloud Run the namespace must be equal to either the project ID or project number. It will default to the resource's project.

      An opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed. May be used for optimistic concurrency, change detection, and the watch operation on a resource or set of resources. They may only be valid for a particular resource or set of resources. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#concurrency-control-and-consistency

      SelfLink is a URL representing this object.

      • uid optional computed - string

      UID is a unique id generated by the server on successful creation of a resource and is not allowed to change on PUT operations. More info: http://kubernetes.io/docs/user-guide/identifiers#uids

    • spec list block

      ContainerConcurrency specifies the maximum allowed in-flight (concurrent) requests per container of the Revision. Values are: - '0' thread-safe, the system should manage the max concurrency. This is the default value. - '1' not-thread-safe. Single concurrency - '2-N' thread-safe, max concurrency of N

      Email address of the IAM service account associated with the revision of the service. The service account represents the identity of the running revision, and determines what permissions the revision has. If not provided, the revision will use the project's default service account.

      ServingState holds a value describing the state the resources are in for this Revision. It is expected that the system will manipulate this based on routability and load.

      TimeoutSeconds holds the max duration the instance is allowed for responding to a request.

  • timeouts single block
  • traffic list block

    LatestRevision may be optionally provided to indicate that the latest ready Revision of the Configuration should be used for this traffic target. When provided LatestRevision must be true if RevisionName is empty; it must be false when RevisionName is non-empty.

    Percent specifies percent of the traffic to this Revision or Configuration.

    RevisionName of a specific revision to which to send this portion of traffic.

Explanation in Terraform Registry

Service acts as a top-level container that manages a set of Routes and Configurations which implement a network service. Service exists to provide a singular abstraction which can be access controlled, reasoned about, and which encapsulates software lifecycle decisions such as rollout policy and team resource ownership. Service acts only as an orchestrator of the underlying Routes and Configurations (much as a kubernetes Deployment orchestrates ReplicaSets). The Service's controller will track the statuses of its owned Configuration and Route, reflecting their statuses and conditions as its own. See also: https://github.com/knative/serving/blob/master/docs/spec/overview.md#service To get more information about Service, see:

  • API documentation
  • How-to Guides
    • Official Documentation

      Warning: google_cloudrun_service creates a Managed Google Cloud Run Service. If you need to create a Cloud Run Service on Anthos(GKE/VMWare) then you will need to create it using the kubernetes alpha provider. Have a look at the Cloud Run Anthos example below.

Frequently asked questions

What is Google Cloud Run Service?

Google Cloud Run Service is a resource for Cloud Run of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud Run Service?

For Terraform, the mike-longledge/ProjectAtyeti, mike-longledge/ProjectAtyeti and theomessin/sandbox source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.