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

CI: validate-example uses local built provider #16388

Merged
merged 3 commits into from
Apr 21, 2022
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
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ teamcity-test:
@$(MAKE) -C .teamcity tools
@$(MAKE) -C .teamcity test

validate-examples:
validate-examples: build
./scripts/validate-examples.sh

pr-check: generate build test lint tflint website-lint
Expand Down
19 changes: 17 additions & 2 deletions scripts/validate-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ exampleDirs=$(find ./examples -mindepth 2 -maxdepth 2 -type d '!' -exec test -e
examplesWithErrors=()
hasError=false

# Setup a local Terraform config file for setting up the dev_overrides for this provider.
terraformrc=$(mktemp)
cat << EOF > $terraformrc
provider_installation {
dev_overrides {
"hashicorp/azurerm" = "$(go env GOPATH)/bin"
}
direct {}
}
EOF

# first check each example validates via `terraform validate`..
for d in $exampleDirs; do
echo "Validating $d.."
exampleHasErrors=false
terraform -chdir=$d init > /dev/null || exampleHasErrors=true
# Though we are using the local built azurerm provider to validate example,
# we still need to call `terraform init` here as examples might contain other providers.
TF_CLI_CONFIG_FILE=$terraformrc terraform -chdir=$d init > /dev/null || exampleHasErrors=true
if ! ${exampleHasErrors}; then
terraform -chdir=$d validate > /dev/null || exampleHasErrors=true
# Always use the local built azurerm provider to validate examples, to avoid examples using
# unreleased features leading to error during CI.
TF_CLI_CONFIG_FILE=$terraformrc terraform -chdir=$d validate > /dev/null || exampleHasErrors=true
fi
if ${exampleHasErrors}; then
examplesWithErrors[${#examplesWithErrors[@]}]=$d
Expand Down