Skip to content

Commit

Permalink
CI: validate-example uses local built provider (hashicorp#16388)
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Apr 21, 2022
1 parent a42a19a commit f908fce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit f908fce

Please sign in to comment.