-
Notifications
You must be signed in to change notification settings - Fork 1
/
script-runner.tf
184 lines (151 loc) · 5.4 KB
/
script-runner.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
data "azurerm_client_config" "current" {}
# Service definitions
resource "azurerm_container_group" "script_runner" {
name = "${var.stack_name}-script-runner-group-${count.index}"
location = var.location
resource_group_name = var.resource_group_name
os_type = "Linux"
count = var.server_count
container {
name = "${var.stack_name}-script-runner-${count.index}"
image = "${var.image}:${var.image_tag}"
commands = [
"sh",
"-c",
"python3 -m gunicorn.app.wsgiapp --timeout 240 --bind 0.0.0.0:$${PORT} --access-logfile - --error-logfile - --workers 4 $${FLASK_APP}",
]
cpu = 1
memory = 1
ports {
port = 80
protocol = "TCP"
}
environment_variables = {
"PORT" = "80"
"FLASK_ENV" = "production"
"PROPAGATE_EXCEPTIONS" = "False"
"AUTH_PROVIDER" = var.auth_provider
"AUTH0_DOMAIN" = var.auth0_domain
"AUTH0_CLIENT_ID" = var.auth0_client_id
"AUTH0_API_AUTHORITY" = "https://${var.auth0_domain}/"
"AUTH0_API_AUDIENCE" = var.auth0_audience
"AUTH0_AUTHORIZATION_URL" = "https://${var.auth0_domain}/authorize"
"AUTH0_TOKEN_URL" = "https://${var.auth0_domain}/oauth/token"
"CELERY_BROKER_URL" = "rediss://:${azurerm_redis_cache.celery_broker.primary_access_key}@${azurerm_redis_cache.celery_broker.hostname}:${azurerm_redis_cache.celery_broker.ssl_port}?ssl_cert_reqs=required"
"CELERY_RESULT_BACKEND" = "rediss://:${azurerm_redis_cache.celery_broker.primary_access_key}@${azurerm_redis_cache.celery_broker.hostname}:${azurerm_redis_cache.celery_broker.ssl_port}?ssl_cert_reqs=required"
}
liveness_probe {
http_get {
path = "/health"
port = 80
scheme = "Http"
}
initial_delay_seconds = 5
period_seconds = 30
}
readiness_probe {
http_get {
path = "/health"
port = 80
scheme = "Http"
}
initial_delay_seconds = 5
period_seconds = 30
}
}
diagnostics {
log_analytics {
workspace_id = azurerm_log_analytics_workspace.script_runner.workspace_id
workspace_key = azurerm_log_analytics_workspace.script_runner.primary_shared_key
}
}
ip_address_type = "public"
tags = {
Terraform = "true"
Environment = "dev"
}
}
# Load Balancers
resource "azurerm_dns_cname_record" "script_runner_lb" {
name = var.dns_subdomain
zone_name = var.dns_zone_name
resource_group_name = var.dns_zone_resource_group_name
ttl = 60
record = "${var.stack_name}-script-runner-lb.azurefd.net"
}
resource "azurerm_frontdoor" "script_runner" {
name = "${var.stack_name}-script-runner-lb"
# location = "Global"
# location = var.location
resource_group_name = var.resource_group_name
enforce_backend_pools_certificate_name_check = false
depends_on = [
azurerm_dns_cname_record.script_runner_lb
]
routing_rule {
name = "${var.stack_name}-script-runner-rr"
accepted_protocols = ["Https"]
patterns_to_match = ["/*"]
frontend_endpoints = [
"${var.stack_name}-script-runner-endpoint-1",
"${var.stack_name}-script-runner-endpoint-2",
]
forwarding_configuration {
forwarding_protocol = "HttpOnly"
backend_pool_name = "${var.stack_name}-script-runner-pool"
}
}
routing_rule {
name = "${var.stack_name}-script-runner-rr-http"
accepted_protocols = ["Http"]
patterns_to_match = ["/*"]
frontend_endpoints = [
"${var.stack_name}-script-runner-endpoint-1",
"${var.stack_name}-script-runner-endpoint-2",
]
redirect_configuration {
redirect_protocol = "HttpsOnly"
redirect_type = "Found"
}
}
backend_pool_load_balancing {
name = "${var.stack_name}-script-runner-lb-settings"
}
backend_pool_health_probe {
name = "${var.stack_name}-script-runner-health-probe"
path = "/health"
}
backend_pool {
name = "${var.stack_name}-script-runner-pool"
dynamic "backend" {
for_each = azurerm_container_group.script_runner
content {
host_header = backend.value["ip_address"]
address = backend.value["ip_address"]
http_port = 80
https_port = 443
}
}
load_balancing_name = "${var.stack_name}-script-runner-lb-settings"
health_probe_name = "${var.stack_name}-script-runner-health-probe"
}
frontend_endpoint {
name = "${var.stack_name}-script-runner-endpoint-1"
host_name = "${var.stack_name}-script-runner-lb.azurefd.net"
}
frontend_endpoint {
name = "${var.stack_name}-script-runner-endpoint-2"
host_name = "${var.dns_subdomain}.${var.dns_zone_name}"
}
}
resource "azurerm_frontdoor_custom_https_configuration" "default" {
frontend_endpoint_id = azurerm_frontdoor.script_runner.frontend_endpoints["${var.stack_name}-script-runner-endpoint-1"]
custom_https_provisioning_enabled = false
}
resource "azurerm_frontdoor_custom_https_configuration" "script_runner" {
frontend_endpoint_id = azurerm_frontdoor.script_runner.frontend_endpoints["${var.stack_name}-script-runner-endpoint-2"]
custom_https_provisioning_enabled = true
custom_https_configuration {
certificate_source = "FrontDoor"
}
}