Skip to content

Commit 0b7c2b5

Browse files
authored
fix: batch processing and reverse location infra changes (#1334)
1 parent c0362b7 commit 0b7c2b5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

infra/functions-python/main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ locals {
3232
vpc_connector_name = lower(var.environment) == "dev" ? "vpc-connector-qa" : "vpc-connector-${lower(var.environment)}"
3333
vpc_connector_project = lower(var.environment) == "dev" ? "mobility-feeds-qa" : var.project_id
3434

35+
# This is as a constant due to the existent of two independent infra modules
36+
batchfunctions_sa_email = "batchfunctions-service-account@${var.project_id}.iam.gserviceaccount.com"
37+
3538
function_process_validation_report_config = jsondecode(file("${path.module}/../../functions-python/process_validation_report/function_config.json"))
3639
function_process_validation_report_zip = "${path.module}/../../functions-python/process_validation_report/.dist/process_validation_report.zip"
3740
public_hosted_datasets_url = lower(var.environment) == "prod" ? "https://${var.public_hosted_datasets_dns}" : "https://${var.environment}-${var.public_hosted_datasets_dns}"
@@ -349,6 +352,10 @@ resource "google_cloudfunctions2_function" "process_validation_report" {
349352
vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"
350353

351354
environment_variables = {
355+
ENV = var.environment
356+
PROJECT_ID = var.project_id
357+
GCP_REGION = var.gcp_region
358+
SERVICE_ACCOUNT_EMAIL = google_service_account.functions_service_account.email
352359
FILES_ENDPOINT = local.public_hosted_datasets_url
353360
# prevents multiline logs from being truncated on GCP console
354361
PYTHONNODEBUGRANGES = 0
@@ -534,6 +541,7 @@ resource "google_cloud_scheduler_job" "gbfs_validator_batch_scheduler" {
534541
headers = {
535542
"Content-Type" = "application/json"
536543
}
544+
body = base64encode("{}")
537545
}
538546
attempt_deadline = "320s"
539547
}
@@ -1060,6 +1068,15 @@ resource "google_cloud_tasks_queue" "reverse_geolocation_task_queue_processor" {
10601068
}
10611069
}
10621070

1071+
# Grant execution permission to bathcfunctions service account to the reverse_geolocation_processor function
1072+
resource "google_cloudfunctions2_function_iam_member" "reverse_geolocation_processor_invoker" {
1073+
project = var.project_id
1074+
location = var.gcp_region
1075+
cloud_function = google_cloudfunctions2_function.reverse_geolocation_processor.name
1076+
role = "roles/cloudfunctions.invoker"
1077+
member = "serviceAccount:${local.batchfunctions_sa_email}"
1078+
}
1079+
10631080
# 13.3 functions/reverse_geolocation - batch cloud function
10641081
resource "google_cloudfunctions2_function" "reverse_geolocation_batch" {
10651082
name = "${local.function_reverse_geolocation_config.name}-batch"
@@ -1161,6 +1178,15 @@ resource "google_cloudfunctions2_function" "tasks_executor" {
11611178
}
11621179
}
11631180

1181+
# Grant execution permission to bathcfunctions service account to the tasks_executor function
1182+
resource "google_cloudfunctions2_function_iam_member" "tasks_executor_invoker" {
1183+
project = var.project_id
1184+
location = var.gcp_region
1185+
cloud_function = google_cloudfunctions2_function.tasks_executor.name
1186+
role = "roles/cloudfunctions.invoker"
1187+
member = "serviceAccount:${local.batchfunctions_sa_email}"
1188+
}
1189+
11641190
# 15. functions/pmtiles_builder cloud function
11651191
resource "google_cloudfunctions2_function" "pmtiles_builder" {
11661192
name = "${local.function_pmtiles_builder_config.name}-${var.environment}"

0 commit comments

Comments
 (0)