nick4fake / terraform-google-event-function

Terraform module for responding to logging events with a function

Home Page:https://registry.terraform.io/modules/terraform-google-modules/event-function/google/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event Function

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.

Compatibility

This module is meant for use with Terraform 0.12. If you haven't upgraded and need a Terraform 0.11.x-compatible version of this module, the last released version intended for Terraform 0.11.x is 0.1.0.

Usage

The automatic-labelling-from-localhost example is a tested reference of how to use the root module with the event-project-log-entry submodule.

Inputs

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

Outputs

Name Description
name The name of the function.

Requirements

The following sections describe the requirements which must be met in order to invoke this module.

Software Dependencies

The following software dependencies must be installed on the system from which this module will be invoked:

IAM Roles

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

APIs

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.

Testing

The fixtures directory and integration directory comprise Terraform modules and InSpec tests used to verify the behaviour of this module.

Testing Software Dependencies

The following software dependencies must be installed on the system from which the tests will be invoked:

Integration Tests

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.

Integration Tests Configuration

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.

Integration Tests Execution

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:

  1. 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/.
  2. Run kitchen create to initialize all Kitchen instances, or run kitchen create <INSTANCE_NAME> to initialize a specific Kitchen instance.
  3. Run kitchen converge to apply all Kitchen instances, or run kitchen converge <INSTANCE_NAME> to apply a specific Kitchen instance.
  4. Run kitchen verify to test all Kitchen instances, or run kitchen verify <INSTANCE_NAME> to test a specific Kitchen instance.
  5. Run kitchen destroy to destroy all Kitchen instances, or run kitchen destroy <INSTANCE_NAME> to destroy a specific Kitchen instance.

Linting

Linters are available for most of the filetypes in this repository.

Linting Software Dependencies

The following software dependencies must be installed on the system from which the linting will be invoked:

Linting Execution

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.

Documentation

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.

Documentation Software Dependencies

The following software dependencies must be installed on the system from which the documentation will be generated:

Generation

Run make generate_docs to update the documentation.

About

Terraform module for responding to logging events with a function

https://registry.terraform.io/modules/terraform-google-modules/event-function/google/

License:Apache License 2.0


Languages

Language:Shell 43.8%Language:HCL 24.3%Language:Python 22.9%Language:Makefile 6.2%Language:Ruby 2.8%