Commit c7422833 authored by John Jarvis's avatar John Jarvis

Make validation work with terraform >= 0.10

Validation checks for variables which fails unless you set a flag that
skips the check. Also removed bash because it isn't really necessary.
parent 56d9d8b2
......@@ -6,24 +6,33 @@ stages:
- deployment
before_script:
- apk add --no-cache bash unzip wget ca-certificates make gnupg && update-ca-certificates
- apk add --no-cache unzip wget ca-certificates make gnupg && update-ca-certificates
tf_validate:
stage: validate
# Validate every directory that contains terraform config
# (`terraform validate` does not do a full recurse)
script: |
#!/bin/bash
#!/bin/sh
envs=$(ls -d environments/*)
for env in $envs; do
TF_VERSION="$(cat "${env}/.terraform_version")" make tfinstall
TF_VERSION="$(cat "${env}/.terraform_version")"
export TF_VERSION
make tfinstall
if echo "$TF_VERSION" | grep -q '\.9\.'; then
# terraform version 0.9.x doesn't support
# the check-variables options but will pass
# with unset vars
tf_opts=""
else
tf_opts="-check-variables=false"
fi
(
cd "$env" || exit
/terraform get
/bin/bash -e -c 'for d in $(find . -name "*.tf" -type f -exec dirname {} \; | sort | uniq); do echo "Checking $d for $0" && /terraform validate "$d"; done' "$env"
/terraform init -backend=false
dirs_to_check=$(find modules "$env" -name "*.tf" -type f -exec dirname {} \; | sort | uniq)
/bin/sh -e -c 'for d in $1; do echo "Checking $d for $0" && /terraform validate $2 "$d"; done' "$env" "$dirs_to_check" "$tf_opts"
)
done
staging_tf_plan:
stage: planning
environment:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment