This module configures a system which responds to events by invoking a Cloud Functions function.
The root module configures a function sourced from a directory on localhost to respond to a given event trigger. The source directory is compressed and uploaded as a Cloud Storage bucket object which will be leveraged by the function.
Alternatively, the repository-function submodule configures a function sourced from a Cloud Source Repositories repository.
The automatic-labelling-from-localhost example is a tested reference of how to use the root module with the event-project-log-entry submodule.
Name | Description | Type | Default | Required |
---|---|---|---|---|
available_memory_mb | The amount of memory in megabytes allotted for the function to use. | string | "256" |
no |
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 | <map> |
no |
event_trigger | A source that fires events in response to a condition in another service. | map | n/a | yes |
labels | A set of key/value label pairs to assign to any lableable resources. | map | <map> |
no |
name | The name to apply to any nameable resources. | string | n/a | yes |
project_id | The ID of the project to which resources will be applied. | string | n/a | yes |
region | The region in which resources will be applied. | string | n/a | yes |
runtime | The runtime in which the function will be executed. | string | "nodejs6" |
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. | string | "60" |
no |
Name | Description |
---|---|
name | The name of the function. |
The following sections describe the requirements which must be met in order to invoke this module.
The following software dependencies must be installed on the system from which this module will be invoked:
- Terraform v0.11.Z
- [Terraform Provider for Archive][terraform-provider-archive-site] v1.2.Z
- Terraform Provider for Google Cloud Platform v2.1.Z
The Service Account which will be used to invoke this module must have the following IAM roles:
- Cloud Functions Developer:
roles/cloudfunctions.developer
- Storage Admin:
roles/storage.admin
The project against which this module will be invoked must have the following APIs enabled:
- Cloud Functions API:
cloudfunctions.googleapis.com
- Cloud Storage API:
storage-component.googleapis.com
The Project Factory module can be used to provision projects with specific APIs activated.
The fixtures directory and integration directory comprise Terraform modules and InSpec tests used to verify the behaviour of this module.
The following software dependencies must be installed on the system from which the tests will be invoked:
Integration tests are invoked using Kitchen, Kitchen-Terraform, and InSpec.
Kitchen instances are configured in the Kitchen configuration file. The instances use the modules in fixtures directory to invoke identically named modules in the examples directory and test this module.
Each Kitchen instance requires a variable file named terraform.tfvars
to be created and populated in the associated test fixture. For
convenience, a [sample variable file][sameple-variable-file] is
available.
A key file for a Service Account with the required
IAM roles must be downloaded from the GCP console and
placed in the root directory of this repository. The key file must be
renamed to credentials.json
.
Run make test_integration_docker
to execute all of the Kitchen
instances in a non-interactive manner within a Docker container.
Alternatively, the Kitchen instances can be invoked interactively:
- Run
make docker_run
to start the Docker container. The root directory of this repository will be mounted in the Docker container at/cft/workdir/
. - Run
kitchen create
to initialize all Kitchen instances, or runkitchen create <INSTANCE_NAME>
to initialize a specific Kitchen instance. - Run
kitchen converge
to apply all Kitchen instances, or runkitchen converge <INSTANCE_NAME>
to apply a specific Kitchen instance. - Run
kitchen verify
to test all Kitchen instances, or runkitchen verify <INSTANCE_NAME>
to test a specific Kitchen instance. - Run
kitchen destroy
to destroy all Kitchen instances, or runkitchen destroy <INSTANCE_NAME>
to destroy a specific Kitchen instance.
Linters are available for most of the filetypes in this repository.
The following software dependencies must be installed on the system from which the linting will be invoked:
Run make check --silent
to execute all of the linters.
Alternatively, the linters can be invoked individually.
- Run
make check_python
to lint Python files. - Run
make check_shell
to lint Shell files. - Run
make check_terraform
to lint Terraform files.
The documentation of inputs and outputs for modules in this repository
is automatically generated in each module's README.md
based on the
contents of the relevant .tf
files.
The following software dependencies must be installed on the system from which the documentation will be generated:
- terraform-docs v0.6.0
Run make generate_docs
to update the documentation.