From c0c6d964fbbc040c4d1d429b28820d79b21fd886 Mon Sep 17 00:00:00 2001 From: Juanadelacuesta <8647634+Juanadelacuesta@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:22:10 +0100 Subject: [PATCH] func: add providers to enos --- enos/enos-terraform.hcl | 10 +++ enos/enos-vars.hcl | 61 ++++++++++++++++++- enos/modules/fetch_artifactory/main.tf | 3 +- .../fetch_artifactory/scripts/install.sh | 19 +++--- 4 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 enos/enos-terraform.hcl diff --git a/enos/enos-terraform.hcl b/enos/enos-terraform.hcl new file mode 100644 index 00000000000..873646e0eb9 --- /dev/null +++ b/enos/enos-terraform.hcl @@ -0,0 +1,10 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +terraform { + required_providers { + enos = { + source = "registry.terraform.io/hashicorp-forge/enos" + } + } +} \ No newline at end of file diff --git a/enos/enos-vars.hcl b/enos/enos-vars.hcl index 6ed72435eb7..b018229acc9 100644 --- a/enos/enos-vars.hcl +++ b/enos/enos-vars.hcl @@ -1,2 +1,61 @@ # Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: BUSL-1.1 \ No newline at end of file +# SPDX-License-Identifier: BUSL-1.1 + +# Variables for the fetch_artifactory module +variable "artifactory_username" { + type = string + description = "The username to use when connecting to artifactory" + default = null +} + +variable "artifactory_token" { + type = string + description = "The token to use when connecting to artifactory" + default = null + sensitive = true +} + +variable "artifactory_host" { + type = string + description = "The artifactory host to search for Nomad artifacts" + default = "https://artifactory.hashicorp.engineering/artifactory" +} + +variable "artifactory_repo" { + type = string + description = "The artifactory repo to search for Nomad artifacts" + default = "hashicorp-crt-stable-local*" +} + +variable "edition" { + type = string + description = "The edition of the binary to search, it can be either CE or ENT" +} + +variable "revision" { + type = string + description = "The specific commit of the binary" +} + +variable "os" { + type = string + description = "The operative system the binary is needed for" + default = "linux" +} + +variable "product_version" { + description = "The version of Nomad we are testing" + type = string + default = null +} + +variable "arch" { + description = "The artifactory path to search for Nomad artifacts" + type = string +} + +variable "binary_path" { + description = "The path to donwload and unzip the binary" + type = string + default = "/home/ubuntu/nomad" +} diff --git a/enos/modules/fetch_artifactory/main.tf b/enos/modules/fetch_artifactory/main.tf index c9c9be8a26f..e380b07401c 100644 --- a/enos/modules/fetch_artifactory/main.tf +++ b/enos/modules/fetch_artifactory/main.tf @@ -17,7 +17,6 @@ data "enos_artifactory_item" "nomad" { path = local.path name = local.artifact_name properties = tomap({ - "commit" = var.revision "product-name" = var.edition == "ce" ? "nomad" : "nomad-enterprise" }) } @@ -30,4 +29,4 @@ resource "enos_local_exec" "install_binary" { } scripts = [abspath("${path.module}/scripts/install.sh")] -} \ No newline at end of file +} \ No newline at end of file diff --git a/enos/modules/fetch_artifactory/scripts/install.sh b/enos/modules/fetch_artifactory/scripts/install.sh index b7d692faed0..9aed88ed48f 100755 --- a/enos/modules/fetch_artifactory/scripts/install.sh +++ b/enos/modules/fetch_artifactory/scripts/install.sh @@ -5,13 +5,15 @@ set -xeuo pipefail # Variables -OUTPUT="nomad.zip" # Name for the downloaded file +LOCAL_ZIP="nomad.zip" # Name for the downloaded file # Download the file -wget --header="X-JFrog-Art-Api:$TOKEN" -O- "$OUTPUT" "$URL" +wget --header="X-JFrog-Art-Api:$TOKEN" -O- "$LOCAL_ZIP" "$URL" # Check if the file was downloaded -if [ $? -nq 0 ]; then +if [ $? -eq 0 ]; then + echo "File downloaded successfully: $LOCAL_ZIP" +else echo "Error downloading file." >&2 exit 1 fi @@ -20,13 +22,12 @@ fi mkdir -p "$BINARY_PATH" # Unzip the file -unzip -o "$OUTPUT" -d "$BINARY_PATH" +unzip -o "$LOCAL_ZIP" -d "$BINARY_PATH" # Check if the file was unzipped -if [ $? -nq 0 ]; then +if [ $? -eq 0 ]; then + echo "File unzipped successfully to $BINARY_PATH" +else echo "Error unzipping file." >&2 exit 1 -fi - -# Remove the zip file -rm $OUTPUT \ No newline at end of file +fi \ No newline at end of file