-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloud_run_service.tf
81 lines (76 loc) · 2.43 KB
/
cloud_run_service.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
resource "google_service_account" "grafana_service_account" {
account_id = "grafana"
display_name = "Grafana service account"
description = "Service account used by Grafana to connect to Cloud Monitoring"
}
resource "google_project_iam_member" "grafana_monitoring_viewer" {
member = "serviceAccount:${google_service_account.grafana_service_account.email}"
role = "roles/monitoring.viewer"
}
resource "google_cloud_run_service" "grafana_service" {
name = var.cloud_run_service_name
location = var.region
autogenerate_revision_name = true
template {
metadata {
annotations = {
"autoscaling.knative.dev/maxScale" = var.cloud_run_max_instances
"run.googleapis.com/vpc-access-connector" = var.serverless_vpc_access_connector_name
"run.googleapis.com/vpc-access-egress" = "private-ranges-only"
}
}
spec {
service_account_name = google_service_account.grafana_service_account.email
containers {
image = var.cloud_run_service_docker_image
resources {
limits = {
cpu : var.cloud_run_service_cpu_limit
memory : var.cloud_run_service_memory_limit
}
}
env {
name = "GF_SERVER_HTTP_PORT"
value = 8080
}
env {
name = "GF_DATABASE_TYPE"
value = "postgres"
}
env {
name = "GF_DATABASE_HOST"
value = google_sql_database_instance.grafana_db_instance.private_ip_address
}
env {
name = "GF_DATABASE_NAME"
value = google_sql_database.grafana_db.name
}
env {
name = "GF_DATABASE_USER"
value = google_sql_user.grafana_db_user.name
}
env {
name = "GF_DATABASE_PASSWORD"
value = google_sql_user.grafana_db_user.password
}
env {
name = "GF_SECURITY_ADMIN_PASSWORD"
value = var.grafana_admin_password
}
}
}
}
}
data "google_iam_policy" "grafana_service_iam_policy" {
binding {
role = "roles/run.invoker"
members = [
"allUsers",
]
}
}
resource "google_cloud_run_service_iam_policy" "grafana_service_iam_policy" {
service = google_cloud_run_service.grafana_service.name
location = google_cloud_run_service.grafana_service.location
policy_data = data.google_iam_policy.grafana_service_iam_policy.policy_data
}