forked from ncihtan/id-provenance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
83 lines (73 loc) · 2.17 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
74
75
76
77
78
79
80
81
82
# Generates an archive of the source code compressed as a .zip file.
data "archive_file" "source" {
type = "zip"
source_dir = "./src"
output_path = "${path.module}/function.zip"
}
# Add source code zip to the Cloud Functions bucket (dcc-cloud-functions)
resource "google_storage_bucket_object" "zip" {
source = data.archive_file.source.output_path
content_type = "application/zip"
name = "src-id-prov-${data.archive_file.source.output_md5}.zip"
bucket = var.dcc_bucket
depends_on = [
data.archive_file.source
]
}
resource "google_pubsub_topic" "default" {
project = var.project_id
name = var.topic_name
}
resource "google_cloud_scheduler_job" "job" {
project = var.project_id
region = var.region
name = var.job_name
description = var.job_description
schedule = var.job_schedule
time_zone = var.time_zone
retry_config {
retry_count = 3
}
pubsub_target {
topic_name = "${google_pubsub_topic.default.id}"
data = base64encode("test")
}
}
resource "google_cloudfunctions2_function" "default" {
project = var.project_id
name = var.function_name
location = var.region
description = "Google Cloud Function to Update ID Provenance BigQuery table"
build_config {
runtime = "python311"
entry_point = "func"
environment_variables = {
BUILD_CONFIG_TEST = "build_test"
}
source {
storage_source {
bucket = var.dcc_bucket
object = google_storage_bucket_object.zip.name
}
}
}
service_config {
max_instance_count = 3
min_instance_count = 1
available_memory = "8G"
timeout_seconds = 540
environment_variables = {
SERVICE_CONFIG_TEST = "config_test"
}
ingress_settings = "ALLOW_INTERNAL_ONLY"
all_traffic_on_latest_revision = true
service_account_email = "${google_service_account.sa.email}"
}
event_trigger {
trigger_region = var.region
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.default.id
retry_policy = "RETRY_POLICY_RETRY"
}
depends_on = [resource.google_service_account.sa]
}