Skip to content

Commit 6e3f2d6

Browse files
feat: Added trigger_http variable to repository-function submodule (#93)
* - Added trigger_http variable to repository-function submodule - Made event_trigger variable optional (either trigger_http OR event_trigger should be supplied) - Added trigger URL to outputs * Correcting whitespace * Adding missing failure pol variable Generate docs Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>
1 parent b4258d5 commit 6e3f2d6

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

modules/repository-function/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ is a tested reference of how to use this submodule with the
2222
| description | The description of the function. | `string` | `"Processes events."` | no |
2323
| entry\_point | The name of a method in the function source which will be invoked when the function is executed. | `string` | n/a | yes |
2424
| environment\_variables | A set of key/value environment variable pairs to assign to the function. | `map(string)` | `{}` | no |
25-
| event\_trigger | A source that fires events in response to a condition in another service. | `map(string)` | n/a | yes |
25+
| event\_trigger | A source that fires events in response to a condition in another service. | `map(string)` | `{}` | no |
26+
| event\_trigger\_failure\_policy\_retry | A toggle to determine if the function should be retried on failure. | `bool` | `false` | no |
2627
| 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 |
2728
| labels | A set of key/value label pairs to assign to any lableable resources. | `map(string)` | `{}` | no |
2829
| name | The name to apply to any nameable resources. | `string` | n/a | yes |
@@ -32,13 +33,15 @@ is a tested reference of how to use this submodule with the
3233
| service\_account\_email | The service account to run the function as. | `string` | `""` | no |
3334
| source\_repository\_url | The URL of the repository which contains the function source code. | `string` | n/a | yes |
3435
| timeout\_s | The amount of time in seconds allotted for the execution of the function. | `number` | `60` | no |
36+
| trigger\_http | Wheter to use HTTP trigger instead of the event trigger. | `bool` | `null` | no |
3537
| 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 |
3638
| 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 |
3739

3840
## Outputs
3941

4042
| Name | Description |
4143
|------|-------------|
44+
| https\_trigger\_url | URL which triggers function execution. |
4245
| name | The name of the function. |
4346

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

modules/repository-function/main.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ resource "google_cloudfunctions_function" "main" {
2121
timeout = var.timeout_s
2222
entry_point = var.entry_point
2323
ingress_settings = var.ingress_settings
24+
trigger_http = var.trigger_http
2425
vpc_connector_egress_settings = var.vpc_connector_egress_settings
2526
vpc_connector = var.vpc_connector
2627

27-
event_trigger {
28-
event_type = var.event_trigger["event_type"]
29-
resource = var.event_trigger["resource"]
28+
dynamic "event_trigger" {
29+
for_each = var.trigger_http != null ? [] : [1]
30+
31+
content {
32+
event_type = var.event_trigger["event_type"]
33+
resource = var.event_trigger["resource"]
34+
35+
failure_policy {
36+
retry = var.event_trigger_failure_policy_retry
37+
}
38+
}
3039
}
3140

3241
labels = var.labels

modules/repository-function/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ output "name" {
1919
value = google_cloudfunctions_function.main.name
2020
}
2121

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+
}

modules/repository-function/variables.tf

Lines changed: 13 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 = {}
@@ -86,6 +93,12 @@ variable "service_account_email" {
8693
description = "The service account to run the function as."
8794
}
8895

96+
variable "event_trigger_failure_policy_retry" {
97+
type = bool
98+
default = false
99+
description = "A toggle to determine if the function should be retried on failure."
100+
}
101+
89102
variable "ingress_settings" {
90103
type = string
91104
default = "ALLOW_ALL"

0 commit comments

Comments
 (0)