chore: add [32m[1mSuccess![0m 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:
parent
c1e196c8b0
commit
9404ad9a53
4
.github/workflows/ci.yaml
vendored
4
.github/workflows/ci.yaml
vendored
@ -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
|
||||
|
||||
@ -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",
|
||||
|
||||
37
scripts/terraform_validate.sh
Executable file
37
scripts/terraform_validate.sh
Executable 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
|
||||
Loading…
x
Reference in New Issue
Block a user