From d6760d4be269a62aa7d379a190036ab5112eb01a Mon Sep 17 00:00:00 2001 From: Juanadelacuesta <8647634+Juanadelacuesta@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:06:05 +0100 Subject: [PATCH] fix: Add clean token to remove extra new line added in provision --- enos/enos-providers.hcl | 3 ++ enos/modules/run_workloads/.gitignore | 2 ++ enos/modules/run_workloads/main.tf | 2 +- .../scripts/wait_for_nomad_api.sh | 25 +++++++++++++ .../templates/docker-service.nomad.hcl | 24 ------------- .../docker-service.nomad.hcl.tpl} | 0 .../templates/exec-system.nomad.hcl | 35 ------------------- .../exec-system.nomad.hcl.tpl} | 4 +-- .../templates/raw-exec-service.nomad.hcl | 35 ------------------- .../raw-exec-service.nomad.hcl.tpl} | 0 enos/modules/run_workloads/variables.tf | 4 +-- enos/modules/test_cluster_health/main.tf | 2 +- 12 files changed, 36 insertions(+), 100 deletions(-) create mode 100644 enos/enos-providers.hcl create mode 100644 enos/modules/run_workloads/.gitignore create mode 100644 enos/modules/run_workloads/scripts/wait_for_nomad_api.sh delete mode 100644 enos/modules/run_workloads/templates/docker-service.nomad.hcl rename enos/modules/run_workloads/{jobs/docker-service.nomad.hcl => templates/docker-service.nomad.hcl.tpl} (100%) delete mode 100644 enos/modules/run_workloads/templates/exec-system.nomad.hcl rename enos/modules/run_workloads/{jobs/exec-system.nomad.hcl => templates/exec-system.nomad.hcl.tpl} (96%) delete mode 100644 enos/modules/run_workloads/templates/raw-exec-service.nomad.hcl rename enos/modules/run_workloads/{jobs/raw-exec-service.nomad.hcl => templates/raw-exec-service.nomad.hcl.tpl} (100%) diff --git a/enos/enos-providers.hcl b/enos/enos-providers.hcl new file mode 100644 index 00000000000..5b7b9275f05 --- /dev/null +++ b/enos/enos-providers.hcl @@ -0,0 +1,3 @@ +provider "aws" "default" { + region = var.aws_region +} diff --git a/enos/modules/run_workloads/.gitignore b/enos/modules/run_workloads/.gitignore new file mode 100644 index 00000000000..a0be4744b64 --- /dev/null +++ b/enos/modules/run_workloads/.gitignore @@ -0,0 +1,2 @@ +# Job specs rendered during the module execution +jobs/*.hcl diff --git a/enos/modules/run_workloads/main.tf b/enos/modules/run_workloads/main.tf index 51075bf9664..0427da7269c 100644 --- a/enos/modules/run_workloads/main.tf +++ b/enos/modules/run_workloads/main.tf @@ -10,7 +10,7 @@ terraform { } locals { - clean_token = trimspace(var.nomad_token) #Somewhere in the process, a newline is added to teh token. + clean_token = trimspace(var.nomad_token) #Somewhere in the process, a newline is added to the token. } resource "enos_local_exec" "wait_for_nomad_api" { diff --git a/enos/modules/run_workloads/scripts/wait_for_nomad_api.sh b/enos/modules/run_workloads/scripts/wait_for_nomad_api.sh new file mode 100644 index 00000000000..55029a11d5d --- /dev/null +++ b/enos/modules/run_workloads/scripts/wait_for_nomad_api.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +set -xeuo pipefail + +TIMEOUT=20 +INTERVAL=5 + +start_time=$(date +%s) + +while ! nomad server members > /dev/null 2>&1; do + echo "Waiting for Nomad API..." + + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + if [ "$elapsed_time" -ge "$TIMEOUT" ]; then + echo "Error: Nomad API did not become available within $TIMEOUT seconds." + exit 1 + fi + + sleep "$INTERVAL" +done + +echo "Nomad API is available!" diff --git a/enos/modules/run_workloads/templates/docker-service.nomad.hcl b/enos/modules/run_workloads/templates/docker-service.nomad.hcl deleted file mode 100644 index f69b060ff0f..00000000000 --- a/enos/modules/run_workloads/templates/docker-service.nomad.hcl +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: BUSL-1.1 - -job "service-docker" { - - group "service-docker" { - count = "${alloc_count}" - task "alpine" { - driver = "docker" - - config { - image = "alpine:latest" - command = "sh" - args = ["-c", "while true; do sleep 300; done"] - - } - - resources { - cpu = 100 - memory = 128 - } - } - } -} diff --git a/enos/modules/run_workloads/jobs/docker-service.nomad.hcl b/enos/modules/run_workloads/templates/docker-service.nomad.hcl.tpl similarity index 100% rename from enos/modules/run_workloads/jobs/docker-service.nomad.hcl rename to enos/modules/run_workloads/templates/docker-service.nomad.hcl.tpl diff --git a/enos/modules/run_workloads/templates/exec-system.nomad.hcl b/enos/modules/run_workloads/templates/exec-system.nomad.hcl deleted file mode 100644 index 37164dbfeed..00000000000 --- a/enos/modules/run_workloads/templates/exec-system.nomad.hcl +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: BUSL-1.1 - -job exec-system { - type = "system" - - group "exec-system" { - count = 1 - - task "exec" { - template { - data = <