feat(terraform): Refactor Alertmanager
[csit.git] / fdio.infra.terraform / 1n_nmd / alertmanager / conf / nomad / alertmanager.hcl.tftpl
@@ -1,28 +1,26 @@
 job "${job_name}" {
   # The "region" parameter specifies the region in which to execute the job.
   # If omitted, this inherits the default region name of "global".
 job "${job_name}" {
   # The "region" parameter specifies the region in which to execute the job.
   # If omitted, this inherits the default region name of "global".
-  # region = "global"
-  #
+  # region    = "${region}"
+
   # The "datacenters" parameter specifies the list of datacenters which should
   # be considered when placing this task. This must be provided.
   # The "datacenters" parameter specifies the list of datacenters which should
   # be considered when placing this task. This must be provided.
-  datacenters         = "${datacenters}"
+  datacenters = "${datacenters}"
 
   # The "type" parameter controls the type of job, which impacts the scheduler's
   # decision on placement. This configuration is optional and defaults to
   # "service". For a full list of job types and their differences, please see
   # the online documentation.
   #
 
   # The "type" parameter controls the type of job, which impacts the scheduler's
   # decision on placement. This configuration is optional and defaults to
   # "service". For a full list of job types and their differences, please see
   # the online documentation.
   #
-  # For more information, please see the online documentation at:
-  #
   #     https://www.nomadproject.io/docs/jobspec/schedulers
   #
   #     https://www.nomadproject.io/docs/jobspec/schedulers
   #
-  type                = "service"
+  type        = "service"
 
   update {
     # The "max_parallel" parameter specifies the maximum number of updates to
     # perform in parallel. In this case, this specifies to update a single task
     # at a time.
 
   update {
     # The "max_parallel" parameter specifies the maximum number of updates to
     # perform in parallel. In this case, this specifies to update a single task
     # at a time.
-    max_parallel      = 1
+    max_parallel      = ${max_parallel}
 
     health_check      = "checks"
 
 
     health_check      = "checks"
 
@@ -56,46 +54,51 @@ job "${job_name}" {
     # Further, setting "canary" equal to the count of the task group allows
     # blue/green deployments. When the job is updated, a full set of the new
     # version is deployed and upon promotion the old version is stopped.
     # Further, setting "canary" equal to the count of the task group allows
     # blue/green deployments. When the job is updated, a full set of the new
     # version is deployed and upon promotion the old version is stopped.
-    canary            = 1
+    canary            = ${canary}
 
     # Specifies if the job should auto-promote to the canary version when all
     # canaries become healthy during a deployment. Defaults to false which means
     # canaries must be manually updated with the nomad deployment promote
     # command.
 
     # Specifies if the job should auto-promote to the canary version when all
     # canaries become healthy during a deployment. Defaults to false which means
     # canaries must be manually updated with the nomad deployment promote
     # command.
-    auto_promote      = true
+    auto_promote      = ${auto_promote}
 
     # The "auto_revert" parameter specifies if the job should auto-revert to the
     # last stable job on deployment failure. A job is marked as stable if all the
     # allocations as part of its deployment were marked healthy.
 
     # The "auto_revert" parameter specifies if the job should auto-revert to the
     # last stable job on deployment failure. A job is marked as stable if all the
     # allocations as part of its deployment were marked healthy.
-    auto_revert       = true
+    auto_revert       = ${auto_revert}
 %{ endif }
   }
 
 %{ endif }
   }
 
-  # The reschedule stanza specifies the group's rescheduling strategy. If
-  # specified at the job level, the configuration will apply to all groups
-  # within the job. If the reschedule stanza is present on both the job and the
-  # group, they are merged with the group stanza taking the highest precedence
-  # and then the job.
-  reschedule {
-    delay             = "30s"
-    delay_function    = "constant"
-    unlimited         = true
+  # All groups in this job should be scheduled on different hosts.
+  constraint {
+    operator = "distinct_hosts"
+    value    = "true"
   }
 
   # The "group" stanza defines a series of tasks that should be co-located on
   # the same Nomad client. Any task within a group will be placed on the same
   # client.
   #
   }
 
   # The "group" stanza defines a series of tasks that should be co-located on
   # the same Nomad client. Any task within a group will be placed on the same
   # client.
   #
-  # For more information and examples on the "group" stanza, please see
-  # the online documentation at:
-  #
   #     https://www.nomadproject.io/docs/job-specification/group
   #
   #     https://www.nomadproject.io/docs/job-specification/group
   #
-  group "prod-group1-${service_name}" {
+  group "${job_name}-group-1" {
     # The "count" parameter specifies the number of the task groups that should
     # be running under this group. This value must be non-negative and defaults
     # to 1.
     # The "count" parameter specifies the number of the task groups that should
     # be running under this group. This value must be non-negative and defaults
     # to 1.
-    count             = ${group_count}
+    count = ${group_count}
+
+    # The volume stanza allows the group to specify that it requires a given
+    # volume from the cluster. The key of the stanza is the name of the volume
+    # as it will be exposed to task configuration.
+    #
+    # https://www.nomadproject.io/docs/job-specification/volume
+    %{ if use_host_volume }
+    volume "${job_name}-volume-1" {
+      type      = "host"
+      read_only = false
+      source    = "${volume_source}"
+    }
+    %{ endif }
 
     # The restart stanza configures a tasks's behavior on task failure. Restarts
     # happen on the client that is running the task.
 
     # The restart stanza configures a tasks's behavior on task failure. Restarts
     # happen on the client that is running the task.
@@ -103,57 +106,75 @@ job "${job_name}" {
     # https://www.nomadproject.io/docs/job-specification/restart
     #
     restart {
     # https://www.nomadproject.io/docs/job-specification/restart
     #
     restart {
-      interval  = "30m"
-      attempts  = 40
-      delay     = "15s"
-      mode      = "delay"
+      interval = "30m"
+      attempts = 40
+      delay    = "15s"
+      mode     = "delay"
     }
 
     # The constraint allows restricting the set of eligible nodes. Constraints
     # may filter on attributes or client metadata.
     #
     }
 
     # The constraint allows restricting the set of eligible nodes. Constraints
     # may filter on attributes or client metadata.
     #
-    # For more information and examples on the "volume" stanza, please see
-    # the online documentation at:
-    #
     #     https://www.nomadproject.io/docs/job-specification/constraint
     #
     constraint {
     #     https://www.nomadproject.io/docs/job-specification/constraint
     #
     constraint {
-      attribute       = "$${attr.cpu.arch}"
-      operator        = "!="
-      value           = "arm64"
+      attribute = "$${attr.cpu.arch}"
+      operator  = "!="
+      value     = "arm64"
     }
 
     constraint {
     }
 
     constraint {
-      attribute      = "$${node.class}"
-      value          = "builder"
+      attribute = "$${node.class}"
+      value     = "builder"
+    }
+
+    # The network stanza specifies the networking requirements for the task
+    # group, including the network mode and port allocations. When scheduling
+    # jobs in Nomad they are provisioned across your fleet of machines along
+    # with other jobs and services. Because you don't know in advance what host
+    # your job will be provisioned on, Nomad will provide your tasks with
+    # network configuration when they start up.
+    #
+    #     https://www.nomadproject.io/docs/job-specification/network
+    #
+    network {
+      port "${service_name}" {
+        static = ${port}
+        to     = ${port}
+      }
     }
 
     # The "task" stanza creates an individual unit of work, such as a Docker
     # container, web application, or batch processing.
     #
     }
 
     # The "task" stanza creates an individual unit of work, such as a Docker
     # container, web application, or batch processing.
     #
-    # For more information and examples on the "task" stanza, please see
-    # the online documentation at:
-    #
     #     https://www.nomadproject.io/docs/job-specification/task
     #
     #     https://www.nomadproject.io/docs/job-specification/task
     #
-    task "prod-task1-${service_name}" {
+    task "${job_name}-task-1" {
       # The "driver" parameter specifies the task driver that should be used to
       # run the task.
       # The "driver" parameter specifies the task driver that should be used to
       # run the task.
-      driver          = "exec"
+      driver = "exec"
+
+    %{ if use_host_volume }
+      volume_mount {
+        volume      = "${job_name}-volume-1"
+        destination = "${volume_destination}"
+        read_only   = false
+      }
+    %{ endif }
 
 
-      %{ if use_vault_provider }
+    %{ if use_vault_provider }
       vault {
       vault {
-        policies        = "${vault_kv_policy_name}"
+        policies = "${vault_kv_policy_name}"
       }
       }
-      %{ endif }
+    %{ endif }
 
       # The "config" stanza specifies the driver configuration, which is passed
       # directly to the driver to start the task. The details of configurations
       # are specific to each driver, so please see specific driver
       # documentation for more information.
       config {
 
       # The "config" stanza specifies the driver configuration, which is passed
       # directly to the driver to start the task. The details of configurations
       # are specific to each driver, so please see specific driver
       # documentation for more information.
       config {
-        command       = "local/alertmanager-${version}.linux-amd64/alertmanager"
-        args          = [
+        command = "local/alertmanager-${version}.linux-amd64/alertmanager"
+        args    = [
           "--config.file=secrets/alertmanager.yml"
         ]
       }
           "--config.file=secrets/alertmanager.yml"
         ]
       }
@@ -163,22 +184,16 @@ job "${job_name}" {
       # popular go-getter library, which permits downloading artifacts from a
       # variety of locations using a URL as the input source.
       #
       # popular go-getter library, which permits downloading artifacts from a
       # variety of locations using a URL as the input source.
       #
-      # For more information and examples on the "artifact" stanza, please see
-      # the online documentation at:
-      #
       #     https://www.nomadproject.io/docs/job-specification/artifact
       #
       artifact {
       #     https://www.nomadproject.io/docs/job-specification/artifact
       #
       artifact {
-        source          = "${url}"
+        source = "${url}"
       }
 
       # The "template" stanza instructs Nomad to manage a template, such as
       # a configuration file or script. This template can optionally pull data
       # from Consul or Vault to populate runtime configuration data.
       #
       }
 
       # The "template" stanza instructs Nomad to manage a template, such as
       # a configuration file or script. This template can optionally pull data
       # from Consul or Vault to populate runtime configuration data.
       #
-      # For more information and examples on the "template" stanza, please see
-      # the online documentation at:
-      #
       #     https://www.nomadproject.io/docs/job-specification/template
       #
       template {
       #     https://www.nomadproject.io/docs/job-specification/template
       #
       template {
@@ -337,15 +352,15 @@ EOH
       #     https://www.nomadproject.io/docs/job-specification/service
       #
       service {
       #     https://www.nomadproject.io/docs/job-specification/service
       #
       service {
-        name            = "${service_name}"
-        port            = "${service_name}"
-        tags            = [ "${service_name}$${NOMAD_ALLOC_INDEX}" ]
+        name       = "${service_name}"
+        port       = "${service_name}"
+        tags       = [ "${service_name}$${NOMAD_ALLOC_INDEX}" ]
         check {
         check {
-          name          = "Alertmanager Check Live"
-          type          = "http"
-          path          = "/-/healthy"
-          interval      = "10s"
-          timeout       = "2s"
+          name     = "Alertmanager Check Live"
+          type     = "http"
+          path     = "/-/healthy"
+          interval = "10s"
+          timeout  = "2s"
         }
       }
 
         }
       }
 
@@ -354,32 +369,12 @@ EOH
       # This ensures the task will execute on a machine that contains enough
       # resource capacity.
       #
       # This ensures the task will execute on a machine that contains enough
       # resource capacity.
       #
-      # For more information and examples on the "resources" stanza, please see
-      # the online documentation at:
-      #
       #     https://www.nomadproject.io/docs/job-specification/resources
       #
       resources {
       #     https://www.nomadproject.io/docs/job-specification/resources
       #
       resources {
-        cpu             = ${cpu}
-        memory          = ${mem}
-        # The network stanza specifies the networking requirements for the task
-        # group, including the network mode and port allocations. When scheduling
-        # jobs in Nomad they are provisioned across your fleet of machines along
-        # with other jobs and services. Because you don't know in advance what host
-        # your job will be provisioned on, Nomad will provide your tasks with
-        # network configuration when they start up.
-        #
-        # For more information and examples on the "template" stanza, please see
-        # the online documentation at:
-        #
-        #     https://www.nomadproject.io/docs/job-specification/network
-        #
-        network {
-          port "${service_name}" {
-            static      = ${port}
-          }
-        }
+        cpu    = ${cpu}
+        memory = ${memory}
       }
     }
   }
       }
     }
   }
-}
\ No newline at end of file
+}