diff --git a/examples/automatic-labelling-from-localhost/function_source/index.js b/examples/automatic-labelling-from-localhost/function_source/index.js index cb2b9bf..76cb207 100644 --- a/examples/automatic-labelling-from-localhost/function_source/index.js +++ b/examples/automatic-labelling-from-localhost/function_source/index.js @@ -110,9 +110,9 @@ storeLabels = * @param {!Object} event Event payload and metadata. * @param {!Function} callback Callback function to signal completion. */ -exports.labelResource = (event, callback) => { +exports.labelResource = (data, context, callback)=> { const eventData = - JSON.parse(Buffer.from(event.data.data, "base64").toString()); + JSON.parse(Buffer.from(data.data, "base64").toString()); console.log("Received event"); console.log(eventData); diff --git a/examples/automatic-labelling-from-localhost/main.tf b/examples/automatic-labelling-from-localhost/main.tf index 7d96f27..fb6917d 100644 --- a/examples/automatic-labelling-from-localhost/main.tf +++ b/examples/automatic-labelling-from-localhost/main.tf @@ -61,6 +61,7 @@ module "localhost_function" { project_id = "${var.project_id}" region = "${var.region}" source_directory = "${path.module}/function_source" + runtime = "nodejs8" } resource "null_resource" "wait_for_function" { diff --git a/examples/automatic-labelling-from-repository/function_source/index.js b/examples/automatic-labelling-from-repository/function_source/index.js index cb2b9bf..76cb207 100644 --- a/examples/automatic-labelling-from-repository/function_source/index.js +++ b/examples/automatic-labelling-from-repository/function_source/index.js @@ -110,9 +110,9 @@ storeLabels = * @param {!Object} event Event payload and metadata. * @param {!Function} callback Callback function to signal completion. */ -exports.labelResource = (event, callback) => { +exports.labelResource = (data, context, callback)=> { const eventData = - JSON.parse(Buffer.from(event.data.data, "base64").toString()); + JSON.parse(Buffer.from(data.data, "base64").toString()); console.log("Received event"); console.log(eventData); diff --git a/examples/automatic-labelling-from-repository/main.tf b/examples/automatic-labelling-from-repository/main.tf index bc4c1be..e0c9b45 100644 --- a/examples/automatic-labelling-from-repository/main.tf +++ b/examples/automatic-labelling-from-repository/main.tf @@ -80,6 +80,7 @@ module "repository_function" { description = "Labels resource with owner information." entry_point = "labelResource" + runtime = "nodejs8" environment_variables = { LABEL_KEY = "principal-email" diff --git a/main.tf b/main.tf index 47ed232..b415013 100644 --- a/main.tf +++ b/main.tf @@ -21,11 +21,12 @@ data "archive_file" "main" { } resource "google_storage_bucket" "main" { - name = "${var.name}" + name = "${coalesce(var.bucket_name, var.name)}" + force_destroy = "${var.bucket_force_destroy}" location = "${var.region}" project = "${var.project_id}" storage_class = "REGIONAL" - labels = "${var.labels}" + labels = "${var.bucket_labels}" } resource "google_storage_bucket_object" "main" { @@ -47,6 +48,10 @@ resource "google_cloudfunctions_function" "main" { event_trigger { event_type = "${var.event_trigger["event_type"]}" resource = "${var.event_trigger["resource"]}" + + failure_policy { + retry = "${var.event_trigger_failure_policy_retry}" + } } labels = "${var.labels}" @@ -56,4 +61,5 @@ resource "google_cloudfunctions_function" "main" { source_archive_object = "${google_storage_bucket_object.main.name}" project = "${var.project_id}" region = "${var.region}" + service_account_email = "${var.service_account_email}" } diff --git a/variables.tf b/variables.tf index 4c5222f..23085b6 100644 --- a/variables.tf +++ b/variables.tf @@ -45,7 +45,7 @@ variable "event_trigger" { variable "labels" { type = "map" default = {} - description = "A set of key/value label pairs to assign to any lableable resources." + description = "A set of key/value label pairs to assign to the Cloud Function." } variable "name" { @@ -65,7 +65,6 @@ variable "region" { variable "runtime" { type = "string" - default = "nodejs6" description = "The runtime in which the function will be executed." } @@ -79,3 +78,33 @@ variable "timeout_s" { default = "60" description = "The amount of time in seconds allotted for the execution of the function." } + +variable "bucket_labels" { + type = "map" + default = {} + description = "A set of key/value label pairs to assign to the function source archive bucket." +} + +variable "service_account_email" { + type = "string" + default = "" + description = "The service account to run the function as." +} + +variable "bucket_name" { + type = "string" + default = "" + description = "The name to apply to the bucket. Will default to a string of the function name." +} + +variable "bucket_force_destroy" { + type = "string" + default = "false" + description = "When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first." +} + +variable "event_trigger_failure_policy_retry" { + type = "string" + default = "false" + description = "A toggle to determine if the function should be retried on failure." +}