-
Notifications
You must be signed in to change notification settings - Fork 12
/
apps.tf
141 lines (122 loc) · 3.93 KB
/
apps.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
locals {
apps = {
"apko" : {
cpu = 1
ram = "512Mi"
container_concurrency = 1
timeout_seconds = 900 # 15m
base_image = "cgr.dev/chainguard/static:latest-glibc"
}
"flatten" : {
cpu = 1
ram = "1Gi"
container_concurrency = 80
timeout_seconds = 120 # 2m
base_image = "cgr.dev/chainguard/static:latest-glibc"
}
"ko" : {
cpu = 2
ram = "4Gi"
container_concurrency = 1
timeout_seconds = 900 # 15m
base_image = "cgr.dev/chainguard/go:latest-dev"
}
"mirror" : {
cpu = 2
ram = "4Gi"
container_concurrency = 1
timeout_seconds = 900 # 15m
base_image = "cgr.dev/chainguard/static:latest-glibc"
}
"random" : {
cpu = 1
ram = "256Mi"
container_concurrency = 1000
timeout_seconds = 60 # 1m
base_image = "cgr.dev/chainguard/static:latest-glibc"
alert_id = module.prober.alert_id
}
wait : {
cpu = 1
ram = "1Gi"
container_concurrency = 80
timeout_seconds = 60 # 1m
base_image = "cgr.dev/chainguard/static:latest-glibc"
}
}
}
resource "ko_build" "image" {
for_each = local.apps
repo = "gcr.io/${var.project_id}/${each.key}"
importpath = "github.com/imjasonh/kontain.me/cmd/${each.key}"
base_image = each.value.base_image
}
resource "google_cloud_run_service" "service" {
for_each = local.apps
name = each.key
location = var.location
template {
spec {
service_account_name = google_service_account.service_account.email
container_concurrency = each.value.container_concurrency
timeout_seconds = each.value.timeout_seconds
containers {
image = ko_build.image[each.key].image_ref
env {
name = "BUCKET"
value = google_storage_bucket.bucket.name
}
resources {
limits = {
cpu = each.value.cpu
memory = each.value.ram
}
requests = {
cpu = each.value.cpu
memory = each.value.ram
}
}
}
}
}
}
data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"
members = ["allUsers"]
}
}
resource "google_cloud_run_service_iam_policy" "noauth" {
for_each = local.apps
location = var.location
service = google_cloud_run_service.service[each.key].name
policy_data = data.google_iam_policy.noauth.policy_data
}
resource "google_cloud_run_domain_mapping" "mapping" {
for_each = local.apps
location = var.location
name = "${each.key}.${var.domain}"
metadata {
namespace = var.project_id
}
spec {
route_name = google_cloud_run_service.service[each.key].name
}
}
resource "google_dns_record_set" "dns-record" {
for_each = local.apps
name = "${each.key}.${var.domain}."
type = google_cloud_run_domain_mapping.mapping[each.key].status[0].resource_records[0].type
ttl = 300
managed_zone = google_dns_managed_zone.zone.name
rrdatas = [google_cloud_run_domain_mapping.mapping[each.key].status[0].resource_records[0].rrdata]
}
resource "null_resource" "test" {
for_each = tomap(local.apps)
depends_on = [google_dns_record_set.dns-record]
# Changes to any service requires re-testing it.
triggers = { service = google_cloud_run_service.service[each.key].id }
provisioner "local-exec" { command = file("${path.module}/cmd/${each.key}/test.sh") }
}
output "cloudrun_url" { value = { for k, _ in local.apps : k => google_cloud_run_service.service[k].status[0].url } }
output "vanity_url" { value = { for k, _ in local.apps : k => google_cloud_run_domain_mapping.mapping[k].name } }