Skip to content

Commit

Permalink
OPS: Add cloud function and update bigquery table in terraform config
Browse files Browse the repository at this point in the history
  • Loading branch information
cortadocodes committed Mar 18, 2024
1 parent 13b9041 commit 5bb5fea
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
42 changes: 30 additions & 12 deletions terraform/bigquery.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "google_bigquery_dataset" "test_dataset" {
dataset_id = "octue_sdk_python_test_dataset"
description = "A dataset for testing BigQuery subscriptions for the Octue SDK."
description = "A dataset for testing storing events for the Octue SDK."
location = "EU"

labels = {
Expand All @@ -19,31 +19,49 @@ resource "google_bigquery_table" "test_table" {
schema = <<EOF
[
{
"name": "subscription_name",
"name": "event",
"type": "JSON",
"mode": "REQUIRED"
},
{
"name": "attributes",
"type": "JSON",
"mode": "REQUIRED"
},
{
"name": "sender",
"type": "STRING",
"mode": "REQUIRED"
},
{
"name": "message_id",
"name": "sender_type",
"type": "STRING",
"mode": "REQUIRED"
},
{
"name": "publish_time",
"type": "TIMESTAMP",
"name": "question_uuid",
"type": "STRING",
"mode": "REQUIRED"
},
{
"name": "data",
"type": "JSON",
"mode": "REQUIRED",
"description": "Octue service event (e.g. heartbeat, log record, result)."
"name": "version",
"type": "STRING",
"mode": "REQUIRED"
},
{
"name": "attributes",
"name": "ordering_key",
"type": "STRING",
"mode": "REQUIRED"
},
{
"name": "backend",
"type": "STRING",
"mode": "REQUIRED"
},
{
"name": "backend_metadata",
"type": "JSON",
"mode": "REQUIRED",
"description": "Metadata for routing the event, adding context, and guiding the receiver's behaviour."
"mode": "REQUIRED"
}
]
EOF
Expand Down
39 changes: 39 additions & 0 deletions terraform/functions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resource "google_cloudfunctions2_function" "event_handler" {
name = "event-handler"
location = var.region
description = "A function for handling events from Octue services."

build_config {
runtime = "python312"
entry_point = "store_pub_sub_event_in_bigquery"
source {
storage_source {
bucket = "twined-gcp"
object = "event_handler_function_source.zip"
}
}
}

service_config {
max_instance_count = 100
available_memory = "256M"
timeout_seconds = 60
environment_variables = {
BIGQUERY_EVENTS_TABLE = "${google_bigquery_dataset.test_dataset.dataset_id}.${google_bigquery_table.test_table.table_id}"
}
}

}


resource "google_cloud_run_service_iam_member" "function_invoker" {
location = google_cloudfunctions2_function.event_handler.location
service = google_cloudfunctions2_function.event_handler.name
role = "roles/run.invoker"
member = "allUsers"
}


output "function_uri" {
value = google_cloudfunctions2_function.event_handler.service_config[0].uri
}

0 comments on commit 5bb5fea

Please sign in to comment.