Skip to content

Commit 2f52072

Browse files
committed
feat: Add function to check for V2 schema directories in tf-validate script
1 parent e73b91f commit 2f52072

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

scripts/tf-validate.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,30 @@ provider_installation {
4747
}
4848
EOF
4949

50+
# Function to check if directory is a V2 schema directory
51+
is_v2_dir() {
52+
local parent_dir="$1"
53+
local v2_dirs=("module_maintainer" "module_user")
54+
55+
for dir in "${v2_dirs[@]}"; do
56+
if [[ $parent_dir =~ $dir ]]; then
57+
return 0 # True
58+
fi
59+
done
60+
return 1 # False
61+
}
62+
5063
for DIR in $(find ./examples -type f -name '*.tf' -exec dirname {} \; | sort -u); do
5164
[ ! -d "$DIR" ] && continue
5265
pushd "$DIR"
5366
echo; echo -e "\e[1;35m===> Example: $DIR <===\e[0m"; echo
54-
terraform init > /dev/null # supress output as it's very verbose
67+
terraform init > /dev/null # suppress output as it's very verbose
5568
terraform fmt -check -recursive
5669

5770
PARENT_DIR=$(basename "$(dirname "$DIR")") # module_maintainer and module_user uses {PARENT_DIR}/vX/main.tf
58-
v2_dirs=("module_maintainer" "module_user")
59-
is_v2_dir=false
60-
for dir in "${v2_dirs[@]}"; do
61-
if [[ $PARENT_DIR =~ $dir ]]; then
62-
is_v2_dir=true
63-
break
64-
fi
65-
done
6671

67-
if $is_v2_dir; then
72+
if is_v2_dir "$PARENT_DIR"; then
73+
echo "v2 schema detected for $DIR"
6874
MONGODB_ATLAS_ADVANCED_CLUSTER_V2_SCHEMA=true terraform validate
6975
else
7076
terraform validate

0 commit comments

Comments
 (0)