Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions examples/automatic-labelling-from-localhost/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions examples/automatic-labelling-from-repository/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module "repository_function" {

description = "Labels resource with owner information."
entry_point = "labelResource"
runtime = "nodejs8"

environment_variables = {
LABEL_KEY = "principal-email"
Expand Down
10 changes: 8 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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}"
Expand All @@ -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}"
}
33 changes: 31 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -65,7 +65,6 @@ variable "region" {

variable "runtime" {
type = "string"
default = "nodejs6"
description = "The runtime in which the function will be executed."
}

Expand All @@ -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."
}