43 lines
3.1 KiB
Markdown
43 lines
3.1 KiB
Markdown
# Scheduled Google Cloud Function Module
|
|
|
|
This module manages a background Cloud Function scheduled via a recurring Cloud Scheduler job. It also manages the required dependencies: a service account for the cloud function with optional IAM bindings, the PubSub topic used for the function trigger, and optionally the GCS bucket used for the code bundle.
|
|
|
|
## Example
|
|
|
|
```hcl
|
|
module "function" {
|
|
source = "./modules/cloud-function-scheduled"
|
|
project_id = "myproject"
|
|
name = "myfunction"
|
|
bundle_config = {
|
|
source_dir = "../cf"
|
|
output_path = "../bundle.zip"
|
|
}
|
|
}
|
|
```
|
|
|
|
<!-- BEGIN TFDOC -->
|
|
## Variables
|
|
|
|
| name | description | type | required | default |
|
|
|---|---|:---: |:---:|:---:|
|
|
| bundle_config | Cloud function code bundle configuration, output path is a zip file. | <code title="object({ source_dir = string output_path = string })">object({...})</code> | ✓ | |
|
|
| name | Name used for resources (schedule, topic, etc.). | <code title="">string</code> | ✓ | |
|
|
| project_id | Project id used for all resources. | <code title="">string</code> | ✓ | |
|
|
| *bucket_name* | Name of the bucket that will be used for the function code, leave null to create one. | <code title="">string</code> | | <code title="">null</code> |
|
|
| *function_config* | Cloud function configuration. | <code title="object({ entry_point = string instances = number memory = number runtime = string timeout = number })">object({...})</code> | | <code title="{ entry_point = "main" instances = 1 memory = 256 runtime = "python37" timeout = 180 }">...</code> |
|
|
| *prefixes* | Optional prefixes for resource ids, null prefixes will be ignored. | <code title="object({ bucket = string function = string job = string service_account = string topic = string })">object({...})</code> | | <code title="">null</code> |
|
|
| *region* | Region used for all resources. | <code title="">string</code> | | <code title="">us-central1</code> |
|
|
| *schedule_config* | Cloud function scheduler job configuration, leave data null to pass the name variable, set schedule to null to disable schedule. | <code title="object({ pubsub_data = string schedule = string time_zone = string })">object({...})</code> | | <code title="{ schedule = "*/10 * * * *" pubsub_data = null time_zone = "UTC" }">...</code> |
|
|
| *service_account_iam_roles* | IAM roles assigned to the service account at the project level. | <code title="list(string)">list(string)</code> | | <code title="">[]</code> |
|
|
|
|
## Outputs
|
|
|
|
| name | description | sensitive |
|
|
|---|---|:---:|
|
|
| bucket_name | Bucket name. | |
|
|
| function_name | Cloud function name. | |
|
|
| service_account_email | Service account email. | |
|
|
| topic_id | PubSub topic id. | |
|
|
<!-- END TFDOC -->
|