Terraform: csit-shim refactor
[csit.git] / resources / tools / terraform / 1n_nmd / prod_storage / prod-nginx.nomad
1 job "prod-nginx" {
2   # The "region" parameter specifies the region in which to execute the job.
3   # If omitted, this inherits the default region name of "global".
4   # region = "global"
5   #
6   # The "datacenters" parameter specifies the list of datacenters which should
7   # be considered when placing this task. This must be provided.
8   datacenters = [ "yul1" ]
9
10   # The "type" parameter controls the type of job, which impacts the scheduler's
11   # decision on placement. This configuration is optional and defaults to
12   # "service". For a full list of job types and their differences, please see
13   # the online documentation.
14   #
15   # For more information, please see the online documentation at:
16   #
17   #     https://www.nomadproject.io/docs/jobspec/schedulers.html
18   #
19   type = "service"
20
21   update {
22     # The "max_parallel" parameter specifies the maximum number of updates to
23     # perform in parallel. In this case, this specifies to update a single task
24     # at a time.
25     max_parallel      = 0
26
27     # The "min_healthy_time" parameter specifies the minimum time the allocation
28     # must be in the healthy state before it is marked as healthy and unblocks
29     # further allocations from being updated.
30     min_healthy_time  = "10s"
31
32     # The "healthy_deadline" parameter specifies the deadline in which the
33     # allocation must be marked as healthy after which the allocation is
34     # automatically transitioned to unhealthy. Transitioning to unhealthy will
35     # fail the deployment and potentially roll back the job if "auto_revert" is
36     # set to true.
37     healthy_deadline  = "3m"
38
39     # The "progress_deadline" parameter specifies the deadline in which an
40     # allocation must be marked as healthy. The deadline begins when the first
41     # allocation for the deployment is created and is reset whenever an allocation
42     # as part of the deployment transitions to a healthy state. If no allocation
43     # transitions to the healthy state before the progress deadline, the
44     # deployment is marked as failed.
45     progress_deadline = "10m"
46
47     # The "auto_revert" parameter specifies if the job should auto-revert to the
48     # last stable job on deployment failure. A job is marked as stable if all the
49     # allocations as part of its deployment were marked healthy.
50     auto_revert       = false
51
52     # The "canary" parameter specifies that changes to the job that would result
53     # in destructive updates should create the specified number of canaries
54     # without stopping any previous allocations. Once the operator determines the
55     # canaries are healthy, they can be promoted which unblocks a rolling update
56     # of the remaining allocations at a rate of "max_parallel".
57     #
58     # Further, setting "canary" equal to the count of the task group allows
59     # blue/green deployments. When the job is updated, a full set of the new
60     # version is deployed and upon promotion the old version is stopped.
61     canary            = 0
62   }
63
64   reschedule {
65     delay             = "2m"
66     delay_function    = "constant"
67     unlimited         = true
68   }
69
70
71   # The "group" stanza defines a series of tasks that should be co-located on
72   # the same Nomad client. Any task within a group will be placed on the same
73   # client.
74   #
75   # For more information and examples on the "group" stanza, please see
76   # the online documentation at:
77   #
78   #     https://www.nomadproject.io/docs/job-specification/group.html
79   #
80   group "prod-group1-nginx" {
81     # The "count" parameter specifies the number of the task groups that should
82     # be running under this group. This value must be non-negative and defaults
83     # to 1.
84     count = 1
85
86     # All groups in this job should be scheduled on different hosts.
87     constraint {
88       operator  = "distinct_hosts"
89       value     = "false"
90     }
91
92     # Prioritize one node.
93     affinity {
94       attribute = "${attr.unique.hostname}"
95       value     = "s46-nomad"
96       weight    = 100
97     }
98
99     # https://www.nomadproject.io/docs/job-specification/volume
100     volume "prod-volume1-storage" {
101       type      = "host"
102       read_only = false
103       source    = "prod-volume-data1-1"
104     }
105
106     # The "task" stanza creates an individual unit of work, such as a Docker
107     # container, web application, or batch processing.
108     #
109     # For more information and examples on the "task" stanza, please see
110     # the online documentation at:
111     #
112     #     https://www.nomadproject.io/docs/job-specification/task.html
113     #
114     task "prod-task1-nginx" {
115       # The "driver" parameter specifies the task driver that should be used to
116       # run the task.
117       driver = "docker"
118
119       volume_mount {
120         volume      = "prod-volume1-storage"
121         destination = "/data/"
122         read_only   = true
123       }
124
125       # The "config" stanza specifies the driver configuration, which is passed
126       # directly to the driver to start the task. The details of configurations
127       # are specific to each driver, so please see specific driver
128       # documentation for more information.
129       config {
130         image        = "nginx:stable"
131         dns_servers  = [ "${attr.unique.network.ip-address}" ]
132         port_map {
133           https      = 443
134         }
135         privileged   = false
136         volumes      = [
137           "/etc/consul.d/ssl/consul.pem:/etc/ssl/certs/nginx-cert.pem",
138           "/etc/consul.d/ssl/consul-key.pem:/etc/ssl/private/nginx-key.pem",
139           "custom/logs.conf:/etc/nginx/conf.d/logs.conf",
140           "custom/docs.conf:/etc/nginx/conf.d/docs.conf"
141         ]
142       }
143
144       # The "template" stanza instructs Nomad to manage a template, such as
145       # a configuration file or script. This template can optionally pull data
146       # from Consul or Vault to populate runtime configuration data.
147       #
148       # For more information and examples on the "template" stanza, please see
149       # the online documentation at:
150       #
151       #     https://www.nomadproject.io/docs/job-specification/template.html
152       #
153       template {
154         data = <<EOH
155           server {
156             listen 443 ssl default_server;
157             server_name logs.nginx.service.consul;
158             keepalive_timeout 70;
159             ssl_session_cache shared:SSL:10m;
160             ssl_session_timeout 10m;
161             ssl_protocols TLSv1.2;
162             ssl_prefer_server_ciphers on;
163             ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384";
164             ssl_certificate /etc/ssl/certs/nginx-cert.pem;
165             ssl_certificate_key /etc/ssl/private/nginx-key.pem;
166             location / {
167               root /data/logs.fd.io;
168               index _;
169               autoindex on;
170               autoindex_exact_size on;
171               autoindex_format html;
172               autoindex_localtime off;
173             }
174             location ~ \.(html.gz)$ {
175               root /data/logs.fd.io;
176               add_header Content-Encoding gzip;
177               add_header Content-Type text/html;
178             }
179             location ~ \.(txt.gz|log.gz)$ {
180               root /data/logs.fd.io;
181               add_header Content-Encoding gzip;
182               add_header Content-Type text/plain;
183             }
184             location ~ \.(xml.gz)$ {
185               root /data/logs.fd.io;
186               add_header Content-Encoding gzip;
187               add_header Content-Type application/xml;
188             }
189           }
190         EOH
191         destination = "custom/logs.conf"
192       }
193       template {
194         data = <<EOH
195           server {
196             listen 443 ssl;
197             server_name docs.nginx.service.consul;
198                 keepalive_timeout 70;
199                 ssl_session_cache shared:SSL:10m;
200                 ssl_session_timeout 10m;
201                 ssl_protocols TLSv1.2;
202                   ssl_prefer_server_ciphers on;
203                 ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384";
204             ssl_certificate /etc/ssl/certs/nginx-cert.pem;
205             ssl_certificate_key /etc/ssl/private/nginx-key.pem;
206             location / {
207               root /data/docs.fd.io;
208               index index.html index.htm;
209             }
210           }
211         EOH
212         destination = "custom/docs.conf"
213       }
214
215       # The service stanza instructs Nomad to register a service with Consul.
216       #
217       # For more information and examples on the "task" stanza, please see
218       # the online documentation at:
219       #
220       #     https://www.nomadproject.io/docs/job-specification/service.html
221       #
222       service {
223         name       = "nginx"
224         port       = "https"
225         tags       = [ "docs", "logs" ]
226       }
227
228       # The "resources" stanza describes the requirements a task needs to
229       # execute. Resource requirements include memory, network, cpu, and more.
230       # This ensures the task will execute on a machine that contains enough
231       # resource capacity.
232       #
233       # For more information and examples on the "resources" stanza, please see
234       # the online documentation at:
235       #
236       #     https://www.nomadproject.io/docs/job-specification/resources.html
237       #
238       resources {
239         cpu        = 1000
240         memory     = 1024
241         network {
242           mode     = "bridge"
243           port "https" {
244             static = 443
245           }
246         }
247       }
248     }
249   }
250 }