Files
nomad/enos/modules/run_workloads/main.tf
Tim Gross 5cc1b4e606 upgrade tests: add transparent proxy workload (#25176)
Add an upgrade test workload for Consul service mesh with transparent
proxy. Note this breaks from the "countdash" demo. The dashboard application
only can verify the backend is up by making a websocket connection, which we
can't do as a health check, and the health check it exposes for that purpose
only passes once the websocket connection has been made. So replace the
dashboard with a minimal nginx reverse proxy to the count-api instead.

Ref: https://hashicorp.atlassian.net/browse/NET-12217
2025-03-07 15:25:26 -05:00

70 lines
2.0 KiB
HCL

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
terraform {
required_providers {
enos = {
source = "hashicorp-forge/enos"
}
}
}
locals {
nomad_env = {
NOMAD_ADDR = var.nomad_addr
NOMAD_CACERT = var.ca_file
NOMAD_CLIENT_CERT = var.cert_file
NOMAD_CLIENT_KEY = var.key_file
NOMAD_TOKEN = var.nomad_token
CONSUL_HTTP_TOKEN = var.consul_token
CONSUL_CACERT = var.ca_file
CONSUL_HTTP_ADDR = var.consul_addr
}
system_job_count = length({ for k, v in var.workloads : k => v if v.type == "system" })
service_batch_allocs = sum([for wl in var.workloads : wl.alloc_count])
}
resource "enos_local_exec" "wait_for_nomad_api" {
environment = local.nomad_env
scripts = [abspath("${path.module}/scripts/wait_for_nomad_api.sh")]
}
resource "enos_local_exec" "get_nodes" {
depends_on = [enos_local_exec.wait_for_nomad_api]
environment = local.nomad_env
inline = ["nomad node status -json | jq '[.[] | select(.SchedulingEligibility == \"eligible\" and .Status == \"ready\")] | length'"]
}
resource "enos_local_exec" "get_jobs" {
depends_on = [enos_local_exec.wait_for_nomad_api]
environment = local.nomad_env
inline = ["nomad job status| awk '$4 == \"running\" {count++} END {print count+0}'"]
}
resource "enos_local_exec" "get_allocs" {
depends_on = [enos_local_exec.wait_for_nomad_api]
environment = local.nomad_env
inline = ["nomad alloc status -json | jq '[.[] | select(.ClientStatus == \"running\")] | length'"]
}
resource "enos_local_exec" "workloads" {
depends_on = [
enos_local_exec.get_jobs,
enos_local_exec.get_allocs,
]
for_each = var.workloads
environment = local.nomad_env
inline = [
each.value.pre_script != null ? abspath("${path.module}/${each.value.pre_script}") : "echo ok",
"nomad job run -var alloc_count=${each.value.alloc_count} ${path.module}/${each.value.job_spec}",
each.value.post_script != null ? abspath("${path.module}/${each.value.post_script}") : "echo ok"
]
}