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
resource "google_cloudfunctions_function" "cl_funct_add" {
name = "cl_funct_add"
description = "ADD function"
runtime = "python37"
resource "google_cloudfunctions_function" "function2" {
provider = google-beta
name = "function-user-adv-query"
description = "My function"
runtime = "nodejs10"
Parameters
-
available_memory_mb
optional - number
Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.
-
build_environment_variables
optional - map from string to string
A set of key/value environment variable pairs available during build time.
-
description
optional - string
Description of the function.
-
entry_point
optional - string
Name of the function that will be executed when the Google Cloud Function is triggered.
-
environment_variables
optional - map from string to string
A set of key/value environment variable pairs to assign to the function.
-
https_trigger_url
optional computed - string
URL which triggers function execution. Returned only if trigger_http is used.
-
id
optional computed - string -
ingress_settings
optional - string
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.
-
max_instances
optional - number
The limit on the maximum number of function instances that may coexist at a given time.
-
name
required - string
A user-defined name of the function. Function names must be unique globally.
-
project
optional computed - string
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.
-
runtime
required - string
The runtime in which the function is going to run. Eg. "nodejs8", "nodejs10", "python37", "go111".
-
service_account_email
optional computed - string
If provided, the self-provided service account to run the function with.
-
source_archive_bucket
optional - string
The GCS bucket containing the zip archive which contains the function.
-
source_archive_object
optional - string
The source archive object (file) in archive bucket.
-
timeout
optional - number
Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.
-
trigger_http
optional - bool
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.
-
vpc_connector
optional - string
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/*.
-
vpc_connector_egress_settings
optional computed - string
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-
event_type
required - string
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.
-
resource
required - string
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-
retry
required - bool
Whether the function should be retried on failure. Defaults to false.
-
-
-
source_repository
list block-
deployed_url
optional computed - string
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.