From 358080d8a126ce7784045459603b6175bc81d03e Mon Sep 17 00:00:00 2001 From: Gonzalo Rojas Date: Fri, 15 May 2026 16:07:21 -0300 Subject: [PATCH] fix(azure-cosmos-db): auto-install tofu when not available in agent PATH Port the same pattern used in the AWS do_tofu scripts: if tofu is not found in PATH, download and cache the binary in /tmp/np-tofu-bin for the pod lifetime. Fixes deployments failing on Azure agents that do not have tofu pre-installed. --- .../azure-cosmos-db/scripts/azure/do_tofu | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/databases/azure-cosmos-db/scripts/azure/do_tofu b/databases/azure-cosmos-db/scripts/azure/do_tofu index 6c2651c..c6e9bc3 100755 --- a/databases/azure-cosmos-db/scripts/azure/do_tofu +++ b/databases/azure-cosmos-db/scripts/azure/do_tofu @@ -4,6 +4,31 @@ set -eoux pipefail env | grep -E '^(AZURE|ARM)' || true +# Ensure tofu is available. On agents where tofu is not pre-installed, download +# and cache the binary in /tmp/np-tofu-bin so it is only fetched once per pod +# lifetime (the directory survives across actions but is cleared on pod restart). +if ! command -v tofu &>/dev/null; then + TOFU_VERSION="1.9.0" + TOFU_BIN_DIR="/tmp/np-tofu-bin" + TOFU_BIN="$TOFU_BIN_DIR/tofu" + + if [ ! -f "$TOFU_BIN" ]; then + echo "tofu not found in PATH, installing v${TOFU_VERSION} to ${TOFU_BIN_DIR}..." + mkdir -p "$TOFU_BIN_DIR" + curl -fsSL \ + "https://github.com/opentofu/opentofu/releases/download/v${TOFU_VERSION}/tofu_${TOFU_VERSION}_linux_amd64.zip" \ + -o /tmp/tofu.zip + unzip -qo /tmp/tofu.zip tofu -d "$TOFU_BIN_DIR" + chmod +x "$TOFU_BIN" + rm -f /tmp/tofu.zip + echo "tofu installed: $("$TOFU_BIN" version | head -1)" + else + echo "Using cached tofu at ${TOFU_BIN}" + fi + + export PATH="$TOFU_BIN_DIR:$PATH" +fi + TOFU_VAR_FILE="$OUTPUT_DIR/terraform.tfvars.json" echo "$TOFU_VARIABLES" > "$TOFU_VAR_FILE"