-
Notifications
You must be signed in to change notification settings - Fork 512
/
camunda.tf
99 lines (91 loc) · 2.79 KB
/
camunda.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Policy to allow public access to Cloud Run endpoint
data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"
members = ["allUsers"]
}
}
# Bind public policy to our Camunda Cloud Run service
resource "google_cloud_run_service_iam_policy" "noauth" {
location = google_cloud_run_service.camunda.location
project = google_cloud_run_service.camunda.project
service = google_cloud_run_service.camunda.name
policy_data = data.google_iam_policy.noauth.policy_data
}
# Create service account to run service
resource "google_service_account" "camunda" {
account_id = "camunda-worker"
display_name = "Camunda Worker"
}
# Give the service account access to Cloud SQL
resource "google_project_iam_member" "project" {
role = "roles/cloudsql.client"
member = "serviceAccount:${google_service_account.camunda.email}"
}
# Cloud Run Camunda service
resource "google_cloud_run_service" "camunda" {
name = "camunda"
location = local.config.region
template {
spec {
# Use locked down Service Account
service_account_name = google_service_account.camunda.email
containers {
image = null_resource.camunda_cloudsql_image.triggers.image
resources {
limits = {
# Default of 256Mb is not enough to start Camunda
memory = "2Gi"
cpu = "1000m"
}
}
env {
name = "DB_URL"
# Complicated DB URL to Cloud SQL
# See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory
value = "jdbc:postgresql:///${google_sql_database.database.name}?cloudSqlInstance=${google_sql_database_instance.camunda-db.connection_name}&socketFactory=com.google.cloud.sql.postgres.SocketFactory"
}
env {
name = "DB_DRIVER"
value = "org.postgresql.Driver"
}
env {
name = "DB_USERNAME"
value = google_sql_user.user.name
}
env {
name = "DB_PASSWORD"
value = google_sql_user.user.password
}
# Test instance of Cloud SQL has low connection limit
# So we turn down the connection pool size
env {
name = "DB_CONN_MAXACTIVE"
value = "5"
}
env {
name = "DB_CONN_MAXIDLE"
value = "5"
}
env {
name = "DB_CONN_MINIDLE"
value = "0"
}
env {
name = "DB_VALIDATE_ON_BORROW"
value = "true"
}
}
}
metadata {
annotations = {
"autoscaling.knative.dev/maxScale" = "1" # no clusting
"run.googleapis.com/cloudsql-instances" = google_sql_database_instance.camunda-db.connection_name
}
}
}
traffic {
percent = 100
latest_revision = true
}
}