-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
67 lines (61 loc) · 1.68 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
resource "random_string" "random" {
length = 16
special = false
}
resource "google_cloud_run_service" "default" {
name = replace("pubsub_to_bq_${split(".", var.bigquery_table)[2]}_${lower(random_string.random.result)}", "_", "-")
location = var.region
template {
spec {
containers {
image = "gcr.io/${var.project}/pubsub-to-bq-consumer:latest"
env {
name = "TABLE_ID"
value = var.bigquery_table
}
resources {
limits = {
memory = "256Mi"
cpu = "1000m"
}
}
}
service_account_name = google_service_account.sa.email
}
metadata {
annotations = {
"run.googleapis.com/ingress" = "all"
"autoscaling.knative.dev/minScale" = "0"
"autoscaling.knative.dev/maxScale" = "10"
}
}
}
traffic {
percent = 100
latest_revision = true
}
}
resource "google_pubsub_subscription" "default" {
name = "pubsub_to_bq_${split(".", var.bigquery_table)[2]}_${lower(random_string.random.result)}"
topic = var.topic_name
push_config {
oidc_token {
service_account_email = google_service_account.sa.email
}
push_endpoint = one(google_cloud_run_service.default.status)["url"]
}
}
data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"
members = [
"serviceAccount:${google_service_account.sa.email}",
]
}
}
resource "google_cloud_run_service_iam_policy" "noauth" {
location = google_cloud_run_service.default.location
project = var.project
service = google_cloud_run_service.default.name
policy_data = data.google_iam_policy.noauth.policy_data
}