chore: add Success! The configuration is valid. (#16)

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
This commit is contained in:
Michael Smith 2025-04-29 09:51:04 -04:00 committed by GitHub
parent c1e196c8b0
commit 9404ad9a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 3 deletions

View File

@ -38,5 +38,7 @@ jobs:
bun-version: latest bun-version: latest
- name: Install dependencies - name: Install dependencies
run: bun install run: bun install
- name: Run tests - name: Run TypeScript tests
run: bun test run: bun test
- name: Run Terraform Validate
run: bun terraform-validate

View File

@ -2,9 +2,9 @@
"name": "modules", "name": "modules",
"scripts": { "scripts": {
"test": "bun test", "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": "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", "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"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "^1.2.9", "@types/bun": "^1.2.9",

37
scripts/terraform_validate.sh Executable file
View File

@ -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