File tree Expand file tree Collapse file tree 6 files changed +45
-8
lines changed
automatic-labelling-from-localhost
automatic-labelling-from-repository Expand file tree Collapse file tree 6 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -110,9 +110,9 @@ storeLabels =
110110 * @param {!Object } event Event payload and metadata.
111111 * @param {!Function } callback Callback function to signal completion.
112112 */
113- exports . labelResource = ( event , callback ) => {
113+ exports . labelResource = ( data , context , callback ) => {
114114 const eventData =
115- JSON . parse ( Buffer . from ( event . data . data , "base64" ) . toString ( ) ) ;
115+ JSON . parse ( Buffer . from ( data . data , "base64" ) . toString ( ) ) ;
116116
117117 console . log ( "Received event" ) ;
118118 console . log ( eventData ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ module "localhost_function" {
6161 project_id = " ${ var . project_id } "
6262 region = " ${ var . region } "
6363 source_directory = " ${ path . module } /function_source"
64+ runtime = " nodejs8"
6465}
6566
6667resource "null_resource" "wait_for_function" {
Original file line number Diff line number Diff line change @@ -110,9 +110,9 @@ storeLabels =
110110 * @param {!Object } event Event payload and metadata.
111111 * @param {!Function } callback Callback function to signal completion.
112112 */
113- exports . labelResource = ( event , callback ) => {
113+ exports . labelResource = ( data , context , callback ) => {
114114 const eventData =
115- JSON . parse ( Buffer . from ( event . data . data , "base64" ) . toString ( ) ) ;
115+ JSON . parse ( Buffer . from ( data . data , "base64" ) . toString ( ) ) ;
116116
117117 console . log ( "Received event" ) ;
118118 console . log ( eventData ) ;
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ module "repository_function" {
8080
8181 description = " Labels resource with owner information."
8282 entry_point = " labelResource"
83+ runtime = " nodejs8"
8384
8485 environment_variables = {
8586 LABEL_KEY = " principal-email"
Original file line number Diff line number Diff line change @@ -21,11 +21,12 @@ data "archive_file" "main" {
2121}
2222
2323resource "google_storage_bucket" "main" {
24- name = " ${ var . name } "
24+ name = " ${ coalesce (var. bucket_name , var. name )} "
25+ force_destroy = " ${ var . bucket_force_destroy } "
2526 location = " ${ var . region } "
2627 project = " ${ var . project_id } "
2728 storage_class = " REGIONAL"
28- labels = " ${ var . labels } "
29+ labels = " ${ var . bucket_labels } "
2930}
3031
3132resource "google_storage_bucket_object" "main" {
@@ -47,6 +48,10 @@ resource "google_cloudfunctions_function" "main" {
4748 event_trigger {
4849 event_type = " ${ var . event_trigger [" event_type" ]} "
4950 resource = " ${ var . event_trigger [" resource" ]} "
51+
52+ failure_policy {
53+ retry = " ${ var . event_trigger_failure_policy_retry } "
54+ }
5055 }
5156
5257 labels = " ${ var . labels } "
@@ -56,4 +61,5 @@ resource "google_cloudfunctions_function" "main" {
5661 source_archive_object = " ${ google_storage_bucket_object . main . name } "
5762 project = " ${ var . project_id } "
5863 region = " ${ var . region } "
64+ service_account_email = " ${ var . service_account_email } "
5965}
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ variable "event_trigger" {
4545variable "labels" {
4646 type = " map"
4747 default = {}
48- description = " A set of key/value label pairs to assign to any lableable resources ."
48+ description = " A set of key/value label pairs to assign to the Cloud Function ."
4949}
5050
5151variable "name" {
@@ -65,7 +65,6 @@ variable "region" {
6565
6666variable "runtime" {
6767 type = " string"
68- default = " nodejs6"
6968 description = " The runtime in which the function will be executed."
7069}
7170
@@ -79,3 +78,33 @@ variable "timeout_s" {
7978 default = " 60"
8079 description = " The amount of time in seconds allotted for the execution of the function."
8180}
81+
82+ variable "bucket_labels" {
83+ type = " map"
84+ default = {}
85+ description = " A set of key/value label pairs to assign to the function source archive bucket."
86+ }
87+
88+ variable "service_account_email" {
89+ type = " string"
90+ default = " "
91+ description = " The service account to run the function as."
92+ }
93+
94+ variable "bucket_name" {
95+ type = " string"
96+ default = " "
97+ description = " The name to apply to the bucket. Will default to a string of the function name."
98+ }
99+
100+ variable "bucket_force_destroy" {
101+ type = " string"
102+ default = " false"
103+ description = " When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first."
104+ }
105+
106+ variable "event_trigger_failure_policy_retry" {
107+ type = " string"
108+ default = " false"
109+ description = " A toggle to determine if the function should be retried on failure."
110+ }
You can’t perform that action at this time.
0 commit comments