Skip to content

Commit 510099e

Browse files
committed
add infra code
1 parent ab808f7 commit 510099e

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

infra/functions-python/main.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ locals {
3636

3737
function_feed_sync_dispatcher_transitland_config = jsondecode(file("${path.module}/../../functions-python/feed_sync_dispatcher_transitland/function_config.json"))
3838
function_feed_sync_dispatcher_transitland_zip = "${path.module}/../../functions-python/feed_sync_dispatcher_transitland/.dist/feed_sync_dispatcher_transitland.zip"
39+
40+
function_operations_api_config = jsondecode(file("${path.module}/../../functions-python/operations_api/function_config.json"))
41+
function_operations_api_zip = "${path.module}/../../functions-python/operations_api/.dist/operations_api.zip"
3942
}
4043

4144
locals {
@@ -116,6 +119,13 @@ resource "google_storage_bucket_object" "feed_sync_dispatcher_transitland_zip" {
116119
source = local.function_feed_sync_dispatcher_transitland_zip
117120
}
118121

122+
# 7. Operations API
123+
resource "google_storage_bucket_object" "operations_api_zip" {
124+
bucket = google_storage_bucket.functions_bucket.name
125+
name = "operations-api-${substr(filebase64sha256(local.function_operations_api_zip), 0, 10)}.zip"
126+
source = local.function_operations_api_zip
127+
}
128+
119129
# Secrets access
120130
resource "google_secret_manager_secret_iam_member" "secret_iam_member" {
121131
for_each = local.unique_secret_keys
@@ -582,6 +592,49 @@ resource "google_cloudfunctions2_function" "feed_sync_dispatcher_transitland" {
582592
}
583593
}
584594

595+
resource "google_cloudfunctions2_function" "operations_api" {
596+
name = "${local.function_operations_api_config.name}"
597+
description = local.function_operations_api_config.description
598+
location = var.gcp_region
599+
depends_on = [google_secret_manager_secret_iam_member.secret_iam_member]
600+
601+
build_config {
602+
runtime = var.python_runtime
603+
entry_point = local.function_operations_api_config.entry_point
604+
source {
605+
storage_source {
606+
bucket = google_storage_bucket.functions_bucket.name
607+
object = google_storage_bucket_object.operations_api_zip.name
608+
}
609+
}
610+
}
611+
service_config {
612+
environment_variables = {
613+
PROJECT_ID = var.project_id
614+
PYTHONNODEBUGRANGES = 0
615+
GOOGLE_CLIENT_ID = var.authorization_google_client_id
616+
}
617+
available_memory = local.function_operations_api_config.available_memory
618+
timeout_seconds = local.function_operations_api_config.timeout
619+
available_cpu = local.function_operations_api_config.available_cpu
620+
max_instance_request_concurrency = local.function_operations_api_config.max_instance_request_concurrency
621+
max_instance_count = local.function_operations_api_config.max_instance_count
622+
min_instance_count = local.function_operations_api_config.min_instance_count
623+
service_account_email = google_service_account.functions_service_account.email
624+
ingress_settings = local.function_operations_api_config.ingress_settings
625+
vpc_connector = data.google_vpc_access_connector.vpc_connector.id
626+
vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"
627+
dynamic "secret_environment_variables" {
628+
for_each = local.function_operations_api_config.secret_environment_variables
629+
content {
630+
key = secret_environment_variables.value["key"]
631+
project_id = var.project_id
632+
secret = "${upper(var.environment)}_${secret_environment_variables.value["key"]}"
633+
version = "latest"
634+
}
635+
}
636+
}
637+
}
585638

586639
# IAM entry for all users to invoke the function
587640
resource "google_cloudfunctions2_function_iam_member" "tokens_invoker" {

infra/functions-python/vars.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ variable "transitland_api_key" {
6969
type = string
7070
description = "Transitland API key"
7171
}
72+
73+
variable "authorization_google_client_id" {
74+
type = string
75+
description = "Google client ID"
76+
}

infra/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ module "functions-python" {
105105
project_id = var.project_id
106106
gcp_region = var.gcp_region
107107
environment = var.environment
108+
108109
transitland_api_key = var.transitland_api_key
109-
validator_endpoint = var.validator_endpoint
110+
authorization_google_client_id = var.oauth2_client_id
110111
}
111112

112113
module "workflows" {

0 commit comments

Comments
 (0)