From 9404ad9a5339d011d0dd0541d1ccf1b7c5e71279 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 29 Apr 2025 09:51:04 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20add=20=1B[32m=1B[1mSuccess!=1B[0m=20Th?= =?UTF-8?q?e=20configuration=20is=20valid.=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More work towards closing https://github.com/coder/internal/issues/532 ## Changes made - Added Bash script to run `terraform validate` on all relevant repos - Updated `package.json` and CI to use the script --- .github/workflows/ci.yaml | 4 +++- package.json | 4 ++-- scripts/terraform_validate.sh | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100755 scripts/terraform_validate.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 159e8c97..1d7b46e6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,5 +38,7 @@ jobs: bun-version: latest - name: Install dependencies run: bun install - - name: Run tests + - name: Run TypeScript tests run: bun test + - name: Run Terraform Validate + run: bun terraform-validate diff --git a/package.json b/package.json index aa3c7e22..08131549 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "modules", "scripts": { "test": "bun test", + "terraform-validate": "./scripts/terraform_validate.sh", "fmt": "bun x prettier -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf", - "fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf", - "update-version": "./update-version.sh" + "fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf" }, "devDependencies": { "@types/bun": "^1.2.9", diff --git a/scripts/terraform_validate.sh b/scripts/terraform_validate.sh new file mode 100755 index 00000000..2c28a0da --- /dev/null +++ b/scripts/terraform_validate.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -euo pipefail + +validate_terraform_directory() { + local dir="$1" + echo "Running \`terraform validate\` in $dir" + pushd "$dir" + terraform init -upgrade + terraform validate + popd +} + +main() { + # Get the directory of the script + local script_dir=$(dirname "$(readlink -f "$0")") + + # Code assumes that registry directory will always be in same position + # relative to the main script directory + local registry_dir="$script_dir/../registry" + + # Get all subdirectories in the registry directory. Code assumes that + # Terraform directories won't begin to appear until three levels deep into + # the registry (e.g., registry/coder/modules/coder-login, which will then + # have a main.tf file inside it) + local subdirs=$(find "$registry_dir" -mindepth 3 -type d | sort) + + for dir in $subdirs; do + # Skip over any directories that obviously don't have the necessary + # files + if test -f "$dir/main.tf"; then + validate_terraform_directory "$dir" + fi + done +} + +main