Skip to content

Commit a6c18a5

Browse files
committed
WIP - Analyst sees that GTFS-RT feeds are updated via workflows
1 parent ea0f44c commit a6c18a5

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed

iac/cal-itp-data-infra-staging/gtfs-rt-archiver/us/.terraform.lock.hcl

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
provider "google" {
2+
project = "cal-itp-data-infra-staging"
3+
}
4+
5+
terraform {
6+
required_providers {
7+
google = {
8+
version = "~> 6.41.0"
9+
}
10+
}
11+
12+
backend "gcs" {
13+
bucket = "calitp-staging-gcp-components-tfstate"
14+
prefix = "cal-itp-data-infra-staging/gtfs-rt-archiver"
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
locals {
2+
workflow_path = "${path.module}/../../../../workflows"
3+
}
4+
5+
data "terraform_remote_state" "iam" {
6+
backend = "gcs"
7+
8+
config = {
9+
bucket = "calitp-staging-gcp-components-tfstate"
10+
prefix = "cal-itp-data-infra-staging/iam"
11+
}
12+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "google_workflows_workflow" "gtfs-rt-archiver" {
2+
name = "gtfs-rt-archiver"
3+
region = "us-west2"
4+
project = "cal-itp-data-infra-staging"
5+
description = "GTFS-RT Archiver"
6+
service_account = data.terraform_remote_state.iam.outputs.google_service_account_composer-service-account_email
7+
source_contents = templatefile("${local.workflow_path}/gtfs-rt.yaml", {})
8+
}
9+
10+
resource "google_cloud_scheduler_job" "gtfs-rt-archiver" {
11+
project = "cal-itp-data-infra-staging"
12+
name = "gtfs-rt-archiver"
13+
description = "Cloud Scheduler GTFS-RT Archiver"
14+
schedule = "*/3 * * * *"
15+
time_zone = "America/Los_Angeles"
16+
attempt_deadline = "320s"
17+
region = "us-west2"
18+
19+
http_target {
20+
http_method = "POST"
21+
uri = "https://workflowexecutions.googleapis.com/v1/${google_workflows_workflow.gtfs-rt-archiver.id}/executions"
22+
body = base64encode(
23+
jsonencode({
24+
"argument" : "{}",
25+
"callLogLevel" : "CALL_LOG_LEVEL_UNSPECIFIED"
26+
})
27+
)
28+
29+
oauth_token {
30+
service_account_email = data.terraform_remote_state.iam.outputs.google_service_account_composer-service-account_email
31+
scope = "https://www.googleapis.com/auth/cloud-platform"
32+
}
33+
}
34+
}

iac/cal-itp-data-infra-staging/iam/us/project_iam_member.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ resource "google_project_iam_member" "composer-service-account" {
294294
project = "cal-itp-data-infra-staging"
295295
}
296296

297+
resource "google_project_iam_member" "workflow-service-account" {
298+
for_each = toset([
299+
"roles/workflows.invoker"
300+
])
301+
role = each.key
302+
member = "serviceAccount:${google_service_account.workflow-service-account.email}"
303+
project = "cal-itp-data-infra-staging"
304+
}
305+
297306
resource "google_project_iam_member" "ms-entra-id-DOT_DDS_Data_Pipeline_and_Warehouse_Users" {
298307
for_each = toset([
299308
"roles/viewer",

iac/cal-itp-data-infra-staging/iam/us/service_account.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ resource "google_service_account" "composer-service-account" {
5858
project = "cal-itp-data-infra-staging"
5959
}
6060

61+
resource "google_service_account" "workflow-service-account" {
62+
account_id = "workflow-service-account"
63+
description = "Service account for Workflow"
64+
disabled = "false"
65+
display_name = "workflow"
66+
project = "cal-itp-data-infra-staging"
67+
}
68+
6169
resource "google_service_account" "sftp-pod-service-account" {
6270
account_id = "sftp-pod-service-account"
6371
description = "Service account for sftp server"

workflows/gtfs-rt.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
main:
2+
steps:
3+
- init:
4+
assign:
5+
- projectId: $${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
6+
- runQuery:
7+
call: googleapis.bigquery.v2.jobs.query
8+
args:
9+
projectId: $${projectId}
10+
body:
11+
useLegacySql: false
12+
useQueryCache: true
13+
timeoutMs: 30000
14+
query: |
15+
SELECT pipeline_url
16+
FROM `cal-itp-data-infra-staging.staging.int_transit_database__gtfs_datasets_dim`
17+
WHERE _is_current = true
18+
LIMIT 1
19+
result: queryResult

0 commit comments

Comments
 (0)