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_mboptional - number
Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.
-
build_environment_variablesoptional - map from string to string
A set of key/value environment variable pairs available during build time.
-
descriptionoptional - string
Description of the function.
-
entry_pointoptional - string
Name of the function that will be executed when the Google Cloud Function is triggered.
-
environment_variablesoptional - map from string to string
A set of key/value environment variable pairs to assign to the function.
-
https_trigger_urloptional computed - string
URL which triggers function execution. Returned only if trigger_http is used.
-
idoptional computed - string -
ingress_settingsoptional - 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.
-
labelsoptional - 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_instancesoptional - number
The limit on the maximum number of function instances that may coexist at a given time.
-
namerequired - string
A user-defined name of the function. Function names must be unique globally.
-
projectoptional computed - string
Project of the function. If it is not provided, the provider project is used.
-
regionoptional computed - string
Region of function. Currently can be only "us-central1". If it is not provided, the provider region is used.
-
runtimerequired - string
The runtime in which the function is going to run. Eg. "nodejs8", "nodejs10", "python37", "go111".
-
service_account_emailoptional computed - string
If provided, the self-provided service account to run the function with.
-
source_archive_bucketoptional - string
The GCS bucket containing the zip archive which contains the function.
-
source_archive_objectoptional - string
The source archive object (file) in archive bucket.
-
timeoutoptional - number
Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.
-
trigger_httpoptional - 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_connectoroptional - 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_settingsoptional 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_triggerlist block-
event_typerequired - 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.
-
resourcerequired - 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_policylist block-
retryrequired - bool
Whether the function should be retried on failure. Defaults to false.
-
-
-
source_repositorylist block-
deployed_urloptional computed - string
The URL pointing to the hosted repository where the function was defined at the time of deployment.
-
urlrequired - string
The URL pointing to the hosted repository where the function is defined.
-
-
timeoutssingle 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.