Skip to content

Commit 9a0918b

Browse files
authored
feat: Adding optional trigger_http input (#56)
* Adding trigger_http input * Use null as the default value for trigger_http * Updating documentation
1 parent c0bac3e commit 9a0918b

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module "localhost_function" {
5959
| description | The description of the function. | string | `"Processes events."` | no |
6060
| entry\_point | The name of a method in the function source which will be invoked when the function is executed. | string | n/a | yes |
6161
| environment\_variables | A set of key/value environment variable pairs to assign to the function. | map(string) | `<map>` | no |
62-
| event\_trigger | A source that fires events in response to a condition in another service. | map(string) | n/a | yes |
62+
| event\_trigger | A source that fires events in response to a condition in another service. | map(string) | `<map>` | no |
6363
| event\_trigger\_failure\_policy\_retry | A toggle to determine if the function should be retried on failure. | bool | `"false"` | no |
6464
| files\_to\_exclude\_in\_source\_dir | Specify files to ignore when reading the source_dir | list(string) | `<list>` | no |
6565
| 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,13 +73,15 @@ module "localhost_function" {
7373
| source\_dependent\_files | A list of any Terraform created `local_file`s that the module will wait for before creating the archive. | object | `<list>` | no |
7474
| source\_directory | The pathname of the directory which contains the function source code. | string | n/a | yes |
7575
| timeout\_s | The amount of time in seconds allotted for the execution of the function. | number | `"60"` | no |
76+
| trigger\_http | Wheter to use HTTP trigger instead of the event trigger. | bool | `"null"` | no |
7677
| 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 |
7778
| 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 |
7879

7980
## Outputs
8081

8182
| Name | Description |
8283
|------|-------------|
84+
| https\_trigger\_url | URL which triggers function execution. |
8385
| name | The name of the function. |
8486

8587
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

main.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ resource "google_cloudfunctions_function" "main" {
7676
timeout = var.timeout_s
7777
entry_point = var.entry_point
7878
ingress_settings = var.ingress_settings
79+
trigger_http = var.trigger_http
7980
vpc_connector_egress_settings = var.vpc_connector_egress_settings
8081
vpc_connector = var.vpc_connector
8182

82-
event_trigger {
83-
event_type = var.event_trigger["event_type"]
84-
resource = var.event_trigger["resource"]
83+
dynamic "event_trigger" {
84+
for_each = var.trigger_http != null ? [] : [1]
8585

86-
failure_policy {
87-
retry = var.event_trigger_failure_policy_retry
86+
content {
87+
event_type = var.event_trigger["event_type"]
88+
resource = var.event_trigger["resource"]
89+
90+
failure_policy {
91+
retry = var.event_trigger_failure_policy_retry
92+
}
8893
}
8994
}
9095

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ output "name" {
1818
description = "The name of the function."
1919
value = google_cloudfunctions_function.main.name
2020
}
21+
22+
output "https_trigger_url" {
23+
description = "URL which triggers function execution."
24+
value = var.trigger_http != null ? google_cloudfunctions_function.main.https_trigger_url : ""
25+
}

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ variable "environment_variables" {
3939

4040
variable "event_trigger" {
4141
type = map(string)
42+
default = {}
4243
description = "A source that fires events in response to a condition in another service."
4344
}
4445

46+
variable "trigger_http" {
47+
type = bool
48+
default = null
49+
description = "Wheter to use HTTP trigger instead of the event trigger."
50+
}
51+
4552
variable "labels" {
4653
type = map(string)
4754
default = {}

0 commit comments

Comments
 (0)