Google Cloud Functions Function

This page shows how to write Terraform for Cloud Functions Function and write them securely.

google_cloudfunctions_function (Terraform)

The Function in Cloud Functions can be configured in Terraform with the resource name google_cloudfunctions_function. The following sections describe 2 examples of how to use the resource and its parameters.

Example Usage from GitHub

cloud_function.tf#L43
resource "google_cloudfunctions_function" "cl_funct_add" {
  name        = "cl_funct_add"
  description = "ADD function"
  runtime     = "python37"


main.tf#L105
resource "google_cloudfunctions_function" "function2" {
  provider = google-beta
  name        = "function-user-adv-query"
  description = "My function"
  runtime     = "nodejs10"

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

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

A set of key/value environment variable pairs available during build time.

Description of the function.

Name of the function that will be executed when the Google Cloud Function is triggered.

A set of key/value environment variable pairs to assign to the function.

URL which triggers function execution. Returned only if trigger_http is used.

String value that controls what traffic can reach the function. Allowed values are ALLOW_ALL and ALLOW_INTERNAL_ONLY. Changes to this field will recreate the cloud function.

  • labels optional - map from string to string

A set of key/value label pairs to assign to the function. Label keys must follow the requirements at https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements.

The limit on the maximum number of function instances that may coexist at a given time.

A user-defined name of the function. Function names must be unique globally.

Project of the function. If it is not provided, the provider project is used.

  • region optional computed - string

Region of function. Currently can be only "us-central1". If it is not provided, the provider region is used.

The runtime in which the function is going to run. Eg. "nodejs8", "nodejs10", "python37", "go111".

If provided, the self-provided service account to run the function with.

The GCS bucket containing the zip archive which contains the function.

The source archive object (file) in archive bucket.

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

Boolean variable. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS. Endpoint is returned as https_trigger_url. Cannot be used with trigger_bucket and trigger_topic.

The VPC Network Connector that this cloud function can connect to. It can be either the fully-qualified URI, or the short name of the network connector resource. The format of this field is projects//locations//connectors/*.

The egress settings for the connector, controlling what traffic is diverted through it. Allowed values are ALL_TRAFFIC and PRIVATE_RANGES_ONLY. Defaults to PRIVATE_RANGES_ONLY. If unset, this field preserves the previously set value.

  • event_trigger list block

    The type of event to observe. For example: "google.storage.object.finalize". See the documentation on calling Cloud Functions for a full reference of accepted triggers.

    The name or partial URI of the resource from which to observe events. For example, "myBucket" or "projects/my-project/topics/my-topic"

    • failure_policy list block

      Whether the function should be retried on failure. Defaults to false.

  • source_repository list block

    The URL pointing to the hosted repository where the function was defined at the time of deployment.

    • url required - string

    The URL pointing to the hosted repository where the function is defined.

  • timeouts single block

Explanation in Terraform Registry

Creates a new Cloud Function. For more information see:

  • API documentation
  • How-to Guides
    • Official Documentation

      Warning: As of November 1, 2019, newly created Functions are private-by-default and will require appropriate IAM permissions to be invoked. See below examples for how to set up the appropriate permissions, or view the Cloud Functions IAM resources for Cloud Functions. resource "google_cloudfunctions_function_iam_member" "invoker" { project = google_cloudfunctions_function.function.project region = google_cloudfunctions_function.function.region cloud_function = google_cloudfunctions_function.function.name role = "roles/cloudfunctions.invoker" member = "allUsers" }

resource "google_cloudfunctions_function_iam_member" "invoker" {
  project        = google_cloudfunctions_function.function.project
  region         = google_cloudfunctions_function.function.region
  cloud_function = google_cloudfunctions_function.function.name
  role   = "roles/cloudfunctions.invoker"
  member = "user:myFunctionInvoker@example.com"
}

Frequently asked questions

What is Google Cloud Functions Function?

Google Cloud Functions Function is a resource for Cloud Functions of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud Functions Function?

For Terraform, the yogeshagrawal11/cloud and khalludi/ice-cream-app 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.