diff --git a/README.md b/README.md index 3cb0828..2d1d7a1 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ module "localhost_function" { | description | The description of the function. | string | `"Processes events."` | no | | entry\_point | The name of a method in the function source which will be invoked when the function is executed. | string | n/a | yes | | environment\_variables | A set of key/value environment variable pairs to assign to the function. | map(string) | `` | no | -| event\_trigger | A source that fires events in response to a condition in another service. | map(string) | n/a | yes | +| event\_trigger | A source that fires events in response to a condition in another service. | map(string) | `` | no | | event\_trigger\_failure\_policy\_retry | A toggle to determine if the function should be retried on failure. | bool | `"false"` | no | | files\_to\_exclude\_in\_source\_dir | Specify files to ignore when reading the source_dir | list(string) | `` | no | | ingress\_settings | The ingress settings for the function. Allowed values are ALLOW_ALL, ALLOW_INTERNAL_AND_GCLB and ALLOW_INTERNAL_ONLY. Changes to this field will recreate the cloud function. | string | `"ALLOW_ALL"` | no | @@ -73,6 +73,7 @@ module "localhost_function" { | source\_dependent\_files | A list of any Terraform created `local_file`s that the module will wait for before creating the archive. | object | `` | no | | source\_directory | The pathname of the directory which contains the function source code. | string | n/a | yes | | timeout\_s | The amount of time in seconds allotted for the execution of the function. | number | `"60"` | no | +| trigger\_http | Wheter to use HTTP trigger instead of the event trigger. | bool | `"null"` | no | | vpc\_connector | The VPC Network Connector that this cloud function can connect to. It should be set up as fully-qualified URI. The format of this field is projects/*/locations/*/connectors/*. | string | `"null"` | no | | vpc\_connector\_egress\_settings | The egress settings for the connector, controlling what traffic is diverted through it. Allowed values are ALL_TRAFFIC and PRIVATE_RANGES_ONLY. If unset, this field preserves the previously set value. | string | `"null"` | no | @@ -80,6 +81,7 @@ module "localhost_function" { | Name | Description | |------|-------------| +| https\_trigger\_url | URL which triggers function execution. | | name | The name of the function. | diff --git a/main.tf b/main.tf index 4a0f553..4ffc649 100644 --- a/main.tf +++ b/main.tf @@ -76,15 +76,20 @@ resource "google_cloudfunctions_function" "main" { timeout = var.timeout_s entry_point = var.entry_point ingress_settings = var.ingress_settings + trigger_http = var.trigger_http vpc_connector_egress_settings = var.vpc_connector_egress_settings vpc_connector = var.vpc_connector - event_trigger { - event_type = var.event_trigger["event_type"] - resource = var.event_trigger["resource"] + dynamic "event_trigger" { + for_each = var.trigger_http != null ? [] : [1] - failure_policy { - retry = var.event_trigger_failure_policy_retry + content { + event_type = var.event_trigger["event_type"] + resource = var.event_trigger["resource"] + + failure_policy { + retry = var.event_trigger_failure_policy_retry + } } } diff --git a/outputs.tf b/outputs.tf index 1923d85..20da896 100644 --- a/outputs.tf +++ b/outputs.tf @@ -18,3 +18,8 @@ output "name" { description = "The name of the function." value = google_cloudfunctions_function.main.name } + +output "https_trigger_url" { + description = "URL which triggers function execution." + value = var.trigger_http != null ? google_cloudfunctions_function.main.https_trigger_url : "" +} diff --git a/variables.tf b/variables.tf index d5ec6d8..473f65a 100644 --- a/variables.tf +++ b/variables.tf @@ -39,9 +39,16 @@ variable "environment_variables" { variable "event_trigger" { type = map(string) + default = {} description = "A source that fires events in response to a condition in another service." } +variable "trigger_http" { + type = bool + default = null + description = "Wheter to use HTTP trigger instead of the event trigger." +} + variable "labels" { type = map(string) default = {}