Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #29 from jetstack/improve-verify
Browse files Browse the repository at this point in the history
Improve verify script
  • Loading branch information
jetstack-bot authored Jul 1, 2019
2 parents 85a3e76 + 2faf474 commit 1da183b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ terraform.tfvars
terraform.tfstate
terraform.tfstate.backup
key.json
verify-terraform/
28 changes: 24 additions & 4 deletions hack/verify-terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

# Capture the output of terraform fmt so that we can trigger the script to
# fail if formatting changes were made. terraform fmt does not consider
# applying formatting changes to be failure, however we want the files to be
# correctly formatted in version control.
FMT=$(terraform fmt $REPO_ROOT)
if [ "$FMT" != "" ]; then
echo "$FMT"
Expand All @@ -40,11 +45,26 @@ sed -i.bak 's|backend "gcs" {}|# backend "gcs" {}|g' main.tf
# Use the local version of the module, not the Terraform Registry version
sed -i.bak 's|source\s=\s"jetstack/gke-cluster/google"|source\s=\s"../"|g' main.tf
sed -i.bak 's|"jetstack/gke-cluster/google"|"../"|g' main.tf

terraform init
VALIDATE=$(terraform validate)
if [ "$VALIDATE" != "" ]; then
echo "$VALIDATE"
exit 1
terraform validate

# TODO: Set up a GCP project and service account to run the following section
# in automated testing.

# To make Terraform plan and apply the the following env vars are required:
# GOOGLE_APPLICATION_CREDENTIALS is the path of a key.json for a service account
# GCP_PROJECT_ID is the ID of a GCP project to use
if [ ! -z ${GCP_PROJECT_ID+x} ] || [ ! -z ${GOOGLE_APPLICATION_CREDENTIALS+x} ]; then
echo $GCP_PROJECT_ID
echo $GOOGLE_APPLICATION_CREDENTIALS
sed -i.bak "s|my-project|$GCP_PROJECT_ID|g" terraform.tfvars
terraform plan
terraform apply -auto-approve
terraform destroy -auto-approve
else
echo "Skipping Terraform plan and apply as GCP_PROJECT_ID and GOOGLE_APPLICATION_CREDENTIALS not set."
fi

popd > /dev/null
rm -rf $REPO_ROOT/verify-terraform

0 comments on commit 1da183b

Please sign in to comment.