Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for conftest in avm modules #82

Merged
merged 7 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions avm_scripts/conftest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -e

has_error=false

if [ ! -d "examples" ]; then
echo "No \`examples\` folder found."
exit 0
fi

cd examples

for d in $(find . -maxdepth 1 -mindepth 1 -type d); do
if ls "$d"/*.tf > /dev/null 2>&1; then
cd "$d"
echo "==> Checking $d"

if [ -f ".e2eignore" ]; then
echo "==> Skipping $d due to .e2eignore file"
cd - >/dev/null 2>&1
continue
fi

echo "==> Initializing Terraform..."
terraform init -input=false
echo "==> Running Terraform plan..."
terraform plan -input=false -out=tfplan.binary
echo "==> Converting Terraform plan to JSON..."
terraform show -json tfplan.binary > tfplan.json

if [ -d "exceptions" ]; then
conftest test --all-namespaces --update git::https://github.com/Azure/policy-library-avm.git//policy/Azure-Proactive-Resiliency-Library-v2 -p policy -p exceptions tfplan.json || has_error=true
else
conftest test --all-namespaces --update git::https://github.com/Azure/policy-library-avm.git//policy/Azure-Proactive-Resiliency-Library-v2 tfplan.json || has_error=true
fi

cd - >/dev/null 2>&1
fi
done

cd ..

if [ "$has_error" = true ]; then
echo "At least one \`examples\` folder failed."
exit 1
fi

echo "All \`examples\` folders passed."
exit 0
4 changes: 4 additions & 0 deletions avmmakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
REMOTE_SCRIPT := https://raw.githubusercontent.com/Azure/tfmod-scaffold/main/avm_scripts$(AVMSCRIPT_VERSION)

.PHONY: conftest
conftest:
curl -H 'Cache-Control: no-cache, no-store' -sSL "$(REMOTE_SCRIPT)/conftest.sh" | bash

.PHONY: docs
docs:
curl -H 'Cache-Control: no-cache, no-store' -sSL "$(REMOTE_SCRIPT)/docs-gen.sh" | bash
Expand Down