Skip to content

Commit 9404ad9

Browse files
chore: add �[32m�[1mSuccess!�[0m The configuration is valid. (#16)
More work towards closing coder/internal#532 ## Changes made - Added Bash script to run `terraform validate` on all relevant repos - Updated `package.json` and CI to use the script
1 parent c1e196c commit 9404ad9

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ jobs:
3838
bun-version: latest
3939
- name: Install dependencies
4040
run: bun install
41-
- name: Run tests
41+
- name: Run TypeScript tests
4242
run: bun test
43+
- name: Run Terraform Validate
44+
run: bun terraform-validate

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "modules",
33
"scripts": {
44
"test": "bun test",
5+
"terraform-validate": "./scripts/terraform_validate.sh",
56
"fmt": "bun x prettier -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf",
6-
"fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf",
7-
"update-version": "./update-version.sh"
7+
"fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf"
88
},
99
"devDependencies": {
1010
"@types/bun": "^1.2.9",

scripts/terraform_validate.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
validate_terraform_directory() {
6+
local dir="$1"
7+
echo "Running \`terraform validate\` in $dir"
8+
pushd "$dir"
9+
terraform init -upgrade
10+
terraform validate
11+
popd
12+
}
13+
14+
main() {
15+
# Get the directory of the script
16+
local script_dir=$(dirname "$(readlink -f "$0")")
17+
18+
# Code assumes that registry directory will always be in same position
19+
# relative to the main script directory
20+
local registry_dir="$script_dir/../registry"
21+
22+
# Get all subdirectories in the registry directory. Code assumes that
23+
# Terraform directories won't begin to appear until three levels deep into
24+
# the registry (e.g., registry/coder/modules/coder-login, which will then
25+
# have a main.tf file inside it)
26+
local subdirs=$(find "$registry_dir" -mindepth 3 -type d | sort)
27+
28+
for dir in $subdirs; do
29+
# Skip over any directories that obviously don't have the necessary
30+
# files
31+
if test -f "$dir/main.tf"; then
32+
validate_terraform_directory "$dir"
33+
fi
34+
done
35+
}
36+
37+
main

0 commit comments

Comments
 (0)