2018-01-19 19:33:07 +00:00
---
layout: "google"
page_title: "Google: google_cloudfunctions_function"
sidebar_current: "docs-google-cloudfunctions-function"
description: |-
Creates a new Cloud Function.
---
# google\_cloudfunctions\_function
Creates a new Cloud Function. For more information see
[the official documentation ](https://cloud.google.com/functions/docs/ )
and
[API ](https://cloud.google.com/functions/docs/apis ).
## Example Usage
```hcl
resource "google_storage_bucket" "bucket" {
name = "test-bucket"
}
resource "google_storage_bucket_object" "archive" {
name = "index.zip"
bucket = "${google_storage_bucket.bucket.name}"
source = "./path/to/zip/file/which/contains/code"
}
resource "google_cloudfunctions_function" "function" {
name = "function-test"
description = "My function"
2019-05-09 22:50:26 +00:00
runtime = "nodejs10"
2018-01-19 19:33:07 +00:00
available_memory_mb = 128
source_archive_bucket = "${google_storage_bucket.bucket.name}"
source_archive_object = "${google_storage_bucket_object.archive.name}"
trigger_http = true
timeout = 60
entry_point = "helloGET"
2018-12-27 15:51:23 +00:00
labels = {
2018-01-19 19:33:07 +00:00
my-label = "my-label-value"
}
2018-12-27 15:51:23 +00:00
environment_variables = {
2018-09-11 00:37:43 +00:00
MY_ENV_VAR = "my-env-var-value"
}
2018-01-19 19:33:07 +00:00
}
```
## Argument Reference
The following arguments are supported:
* `name` - (Required) A user-defined name of the function. Function names must be unique globally.
2019-05-09 22:50:26 +00:00
* `runtime` - (Optional) The runtime in which the function is going to run. One
of `"nodejs6"` , `"nodejs8"` , `"nodejs10"` , `"python37"` , `"go111"` . If empty,
defaults to `"nodejs6"` . It's recommended that you override the default, as
`"nodejs6"` is deprecated.
2018-01-19 19:33:07 +00:00
- - -
* `description` - (Optional) Description of the function.
* `available_memory_mb` - (Optional) Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.
* `timeout` - (Optional) Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.
2018-11-14 19:28:08 +00:00
* `entry_point` - (Optional) Name of the function that will be executed when the Google Cloud Function is triggered.
2018-01-19 19:33:07 +00:00
2018-10-03 18:15:45 +00:00
* `event_trigger` - (Optional) A source that fires events in response to a condition in another service. Structure is documented below. Cannot be used with `trigger_http` .
2018-01-19 19:33:07 +00:00
* `trigger_http` - (Optional) 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` .
* `labels` - (Optional) A set of key/value label pairs to assign to the function.
2019-01-28 22:39:37 +00:00
* `service_account_email` - (Optional) If provided, the self-provided service account to run the function with.
2018-09-11 00:37:43 +00:00
* `environment_variables` - (Optional) A set of key/value environment variable pairs to assign to the function.
2018-12-13 01:57:01 +00:00
* `source_archive_bucket` - (Optional) The GCS bucket containing the zip archive which contains the function.
* `source_archive_object` - (Optional) The source archive object (file) in archive bucket.
* `source_repository` - (Optional) Represents parameters related to source repository where a function is hosted.
Cannot be set alongside `source_archive_bucket` or `source_archive_object` . Structure is documented below.
2019-04-29 17:59:02 +00:00
* `max_instances` - (Optional) The limit on the maximum number of function instances that may coexist at a given time.
2018-10-03 18:15:45 +00:00
The `event_trigger` block supports:
2018-11-06 17:30:19 +00:00
* `event_type` - (Required) The type of event to observe. For example: `"google.storage.object.finalize"` .
See the documentation on [calling Cloud Functions ](https://cloud.google.com/functions/docs/calling/ ) for a full reference.
2018-11-21 05:34:02 +00:00
Cloud Storage, Cloud Pub/Sub and Cloud Firestore triggers are supported at this time.
Legacy triggers are supported, such as `"providers/cloud.storage/eventTypes/object.change"` ,
`"providers/cloud.pubsub/eventTypes/topic.publish"` and `"providers/cloud.firestore/eventTypes/document.create"` .
2018-10-03 18:15:45 +00:00
* `resource` - (Required) Required. The name of the resource from which to observe events, for example, `"myBucket"`
2018-10-03 19:42:18 +00:00
* `failure_policy` - (Optional) Specifies policy for failed executions. Structure is documented below.
2018-10-03 18:15:45 +00:00
The `failure_policy` block supports:
2018-10-03 19:42:18 +00:00
* `retry` - (Required) Whether the function should be retried on failure. Defaults to `false` .
2018-05-09 20:57:54 +00:00
2019-03-07 16:53:33 +00:00
The `source_repository` block supports:
2018-12-13 01:57:01 +00:00
* `url` - (Required) The URL pointing to the hosted repository where the function is defined. There are supported Cloud Source Repository URLs in the following formats:
* To refer to a specific commit: `https://source.developers.google.com/projects/*/repos/*/revisions/*/paths/*`
* To refer to a moveable alias (branch): `https://source.developers.google.com/projects/*/repos/*/moveable-aliases/*/paths/*` . To refer to HEAD, use the `master` moveable alias.
* To refer to a specific fixed alias (tag): `https://source.developers.google.com/projects/*/repos/*/fixed-aliases/*/paths/*`
2018-01-19 19:33:07 +00:00
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are
exported:
* `https_trigger_url` - URL which triggers function execution. Returned only if `trigger_http` is used.
2019-03-07 16:53:33 +00:00
* `source_repository.0.deployed_url` - The URL pointing to the hosted repository where the function was defined at the time of deployment.
2018-12-13 01:57:01 +00:00
2018-01-19 19:33:07 +00:00
* `project` - Project of the function. If it is not provided, the provider project is used.
* `region` - Region of function. Currently can be only "us-central1". If it is not provided, the provider region is used.
2019-02-22 01:53:27 +00:00
## Timeouts
This resource provides the following
[Timeouts ](/docs/configuration/resources.html#timeouts ) configuration options:
- `create` - Default is 5 minutes.
- `update` - Default is 5 minutes.
- `delete` - Default is 5 minutes.
2018-01-19 19:33:07 +00:00
## Import
Functions can be imported using the `name` , e.g.
```
$ terraform import google_cloudfunctions_function.default function-test
```