This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
73 lines (65 loc) · 2.56 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Archive Cloud Functions' source code.
data "archive_file" "functions" {
type = "zip"
source_dir = "${path.module}/functions"
output_path = "functions.zip"
}
# Cloud Storage bucket to save Cloud Functions' source code.
resource "google_storage_bucket" "functions" {
name = "${var.project_id}-ai-platform-notification"
location = var.region
project = var.project_id
storage_class = "regional"
}
resource "google_storage_bucket_object" "functions" {
name = "${data.archive_file.functions.output_md5}.zip"
bucket = google_storage_bucket.functions.name
source = data.archive_file.functions.output_path
}
resource "google_cloudfunctions_function" "function" {
name = "ai-platform-notification"
description = "Cloud Functions to check AI Platform log messages."
runtime = "python38"
available_memory_mb = 128
source_archive_bucket = google_storage_bucket.functions.name
source_archive_object = google_storage_bucket_object.functions.name
entry_point = "main"
project = var.project_id
region = var.region
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = google_pubsub_topic.ai_platform_log.id
}
# environment_variables = {
# TARGET_TOPIC = google_pubsub_topic.ai_platform_notification.id
# }
}
# Pub/Sub topic to receive AI Platform logs.
resource "google_pubsub_topic" "ai_platform_log" {
name = "ai-platform-log"
project = var.project_id
}
# # Pub/Sub topic to receive push notifications from Cloud Run.
# resource "google_pubsub_topic" "ai_platform_notification" {
# name = "ai-platform-notification"
# project = var.project_id
# }
# # Service account to push message to Cloud Run.
# resource "google_service_account" "pubsub_sa" {
# project = var.project_id
# account_id = "ai-platform-notification"
# }
# Log sink to send AI Platform logs to Stackdriver Logging.
resource "google_logging_project_sink" "ai_platform_log" {
name = "ai-platform-log"
project = var.project_id
destination = "pubsub.googleapis.com/${google_pubsub_topic.ai_platform_log.id}"
filter = "resource.type=ml_job AND resource.labels.task_name=service"
unique_writer_identity = true
}
resource "google_pubsub_topic_iam_member" "log_sink_sa" {
project = google_pubsub_topic.ai_platform_log.project
topic = google_pubsub_topic.ai_platform_log.name
role = "roles/pubsub.publisher"
member = google_logging_project_sink.ai_platform_log.writer_identity
}