Skip to content

Commit 4d4bcb2

Browse files
authored
Merge pull request #965 from wiktorn/cloud_functions_trigger_v2_optionals
Add triggers to Cloud Functions v2
2 parents df539b5 + 0121806 commit 4d4bcb2

File tree

12 files changed

+264
-144
lines changed

12 files changed

+264
-144
lines changed

blueprints/cloud-operations/asset-inventory-feed-remediation/main.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,18 @@ module "cf" {
7979
name = var.name
8080
bucket_name = "${var.name}-${random_pet.random.id}"
8181
bucket_config = {
82-
location = var.region
83-
lifecycle_delete_age = null
82+
location = var.region
8483
}
8584
bundle_config = {
8685
source_dir = "cf"
8786
output_path = var.bundle_path
88-
excludes = null
8987
}
9088
service_account = module.service-account.email
9189
trigger_config = {
92-
event = "google.pubsub.topic.publish"
93-
resource = module.pubsub.topic.id
94-
retry = null
90+
v1 = {
91+
event = "google.pubsub.topic.publish"
92+
resource = module.pubsub.topic.id
93+
}
9594
}
9695
}
9796

blueprints/cloud-operations/network-dashboard/main.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,21 @@ module "cloud-function" {
137137
name = "network-dashboard-cloud-function"
138138
bucket_name = "${local.monitoring_project}-network-dashboard-bucket"
139139
bucket_config = {
140-
location = var.region
141-
lifecycle_delete_age = null
140+
location = var.region
142141
}
143142
region = var.region
144143

145144
bundle_config = {
146145
source_dir = "cloud-function"
147146
output_path = "cloud-function.zip"
148-
excludes = null
149147
}
150148

151149
function_config = {
152150
timeout = 480 # Timeout in seconds, increase it if your CF timeouts and use v2 if > 9 minutes.
153151
entry_point = "main"
154152
runtime = "python39"
155153
instances = 1
156-
memory = 256 # Memory in MB
154+
memory_mb = 256
157155

158156
}
159157

@@ -169,10 +167,17 @@ module "cloud-function" {
169167
# Internal only doesn't seem to work with CFv2:
170168
ingress_settings = var.cf_version == "V2" ? "ALLOW_ALL" : "ALLOW_INTERNAL_ONLY"
171169

172-
trigger_config = {
173-
event = "google.pubsub.topic.publish"
174-
resource = module.pubsub.topic.id
175-
retry = null
170+
trigger_config = var.cf_version == "V2" ? {
171+
v2 = {
172+
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
173+
pubsub_topic = module.pubsub.topic.id
174+
service_account_create = true
175+
}
176+
} : {
177+
v1 = {
178+
event = "google.pubsub.topic.publish"
179+
resource = module.pubsub.topic.id
180+
}
176181
}
177182
}
178183

blueprints/cloud-operations/quota-monitoring/main.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ module "cf" {
5252
name = var.name
5353
bucket_name = "${var.name}-${random_pet.random.id}"
5454
bucket_config = {
55-
location = var.region
56-
lifecycle_delete_age = null
55+
location = var.region
5756
}
5857
bundle_config = {
5958
source_dir = "cf"
6059
output_path = var.bundle_path
61-
excludes = null
6260
}
6361
# https://github.com/hashicorp/terraform-provider-archive/issues/40
6462
# https://issuetracker.google.com/issues/155215191
@@ -68,9 +66,10 @@ module "cf" {
6866
}
6967
service_account_create = true
7068
trigger_config = {
71-
event = "google.pubsub.topic.publish"
72-
resource = module.pubsub.topic.id
73-
retry = null
69+
v1 = {
70+
event = "google.pubsub.topic.publish"
71+
resource = module.pubsub.topic.id
72+
}
7473
}
7574
}
7675

blueprints/cloud-operations/scheduled-asset-inventory-export-bq/main.tf

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,18 @@ module "cf" {
9191
name = var.name
9292
bucket_name = "${var.name}-${random_pet.random.id}"
9393
bucket_config = {
94-
location = var.region
95-
lifecycle_delete_age = null
94+
location = var.region
9695
}
9796
bundle_config = {
9897
source_dir = "cf"
9998
output_path = var.bundle_path
100-
excludes = null
10199
}
102100
service_account = module.service-account.email
103101
trigger_config = {
104-
event = "google.pubsub.topic.publish"
105-
resource = module.pubsub.topic.id
106-
retry = null
102+
v1 = {
103+
event = "google.pubsub.topic.publish"
104+
resource = module.pubsub.topic.id
105+
}
107106
}
108107
}
109108

@@ -115,8 +114,8 @@ module "cffile" {
115114
name = var.name_cffile
116115
bucket_name = "${var.name_cffile}-${random_pet.random.id}"
117116
bucket_config = {
118-
location = var.region
119-
lifecycle_delete_age = null
117+
location = var.region
118+
lifecycle_delete_age_days = null
120119
}
121120
bundle_config = {
122121
source_dir = "cffile"
@@ -125,9 +124,11 @@ module "cffile" {
125124
}
126125
service_account = module.service-account.email
127126
trigger_config = {
128-
event = "google.pubsub.topic.publish"
129-
resource = module.pubsub_file.topic.id
130-
retry = null
127+
v1 = {
128+
event = "google.pubsub.topic.publish"
129+
resource = module.pubsub_file.topic.id
130+
retry = null
131+
}
131132
}
132133
}
133134

blueprints/cloud-operations/unmanaged-instances-healthcheck/main.tf

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,28 @@ module "cf-restarter" {
114114
region = var.region
115115
bucket_name = "cf-bundle-bucket-${random_pet.random.id}"
116116
bucket_config = {
117-
location = var.region
118-
lifecycle_delete_age = null
117+
location = var.region
119118
}
120119
bundle_config = {
121120
source_dir = "${path.module}/function/restarter"
122121
output_path = "restarter.zip"
123-
excludes = []
124122
}
125123
service_account = module.service-account-restarter.email
126124

127125
function_config = {
128126
entry_point = "RestartInstance"
129127
ingress_settings = null
130-
instances = 1
131-
memory = 256
128+
instance_count = 1
129+
memory_mb = 256
132130
runtime = "go116"
133131
timeout = 300
134132
}
135133

136134
trigger_config = {
137-
event = "google.pubsub.topic.publish"
138-
resource = module.pubsub.topic.id
139-
retry = null
135+
v1 = {
136+
event = "google.pubsub.topic.publish"
137+
resource = module.pubsub.topic.id
138+
}
140139
}
141140

142141
}
@@ -151,15 +150,14 @@ module "cf-healthchecker" {
151150
bundle_config = {
152151
source_dir = "${path.module}/function/healthchecker"
153152
output_path = "healthchecker.zip"
154-
excludes = []
155153
}
156154
service_account = module.service-account-healthchecker.email
157155

158156
function_config = {
159157
entry_point = "HealthCheck"
160158
ingress_settings = null
161-
instances = 1
162-
memory = 256
159+
instance_count = 1
160+
memory_mb = 256
163161
runtime = "go116"
164162
timeout = 300
165163
}

blueprints/networking/private-cloud-function-from-onprem/main.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,9 @@ module "function-hello" {
195195
bundle_config = {
196196
source_dir = "${path.module}/assets"
197197
output_path = "bundle.zip"
198-
excludes = null
199198
}
200199
bucket_config = {
201-
location = var.region
202-
lifecycle_delete_age = null
200+
location = var.region
203201
}
204202
iam = {
205203
"roles/cloudfunctions.invoker" = ["allUsers"]

blueprints/serverless/api-gateway/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ module "functions" {
7070
region = each.value
7171
ingress_settings = "ALLOW_ALL"
7272
bucket_config = {
73-
location = null
74-
lifecycle_delete_age = 1
73+
location = null
74+
lifecycle_delete_age_days = 1
7575
}
7676
bundle_config = {
7777
source_dir = "${path.module}/function"

0 commit comments

Comments
 (0)