Commit 7743672d authored by Alejandro Rodriguez's avatar Alejandro Rodriguez

Change to each directory to run `tf-lint` properly

parent 561e2bc5
......@@ -7,7 +7,7 @@ stages:
- deployment
before_script:
- apk add --no-cache unzip wget ca-certificates make gnupg ruby build-base ruby-dev && update-ca-certificates
- apk add --no-cache unzip wget ca-certificates make gnupg ruby build-base ruby-dev openssh-client git && update-ca-certificates
- gem install --no-rdoc --no-ri terraform_landscape json multi_json
# Terraform requires a key file for TF_VAR_ssh_key. We don't really use it
# but it has to be there.
......@@ -33,13 +33,28 @@ tf_validate:
# (`terraform validate` does not do a full recurse)
script: |
#!/bin/sh
envs=$(ls -d environments/*)
# SSH setup for module cloning
eval $(ssh-agent -s)
echo "$SSH_PRIVATE_KEY" | base64 -d | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
cp private/env_vars/common.env.example private/env_vars/common.env
dir="environments" # For the "bin/tf-set-env" script
envs=$(ls -d $dir/*)
for env in $envs; do
tf_opts="-check-variables=false"
(
/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" && tflint --error-with-issues $2; done' "$env" "$dirs_to_check" "$tf_opts"
environment=$(basename "$env") # Also used on the "bin/tf-set-env" script
cp private/env_vars/environment.env.example private/env_vars/$environment.env
source "bin/tf-set-env"
/bin/sh -e -c 'for d in $1; do (cd $d && echo "Checking $d for $0" && /terraform init -backend=false && /terraform validate $2 && tflint --error-with-issues); done' "$env" "$dirs_to_check" "$tf_opts"
)
done
......
......@@ -4,3 +4,5 @@
!.gitignore
!example.tfvars
!example.env
!common.env.example
!environment.env.example
### Set the following variables to the correct paths values for you
export GITLAB_CHEF_REPO_DIR=""
export GITLAB_CHEF_USER=""
export GITLAB_SSH_PRIVATE_KEY=""
export GITLAB_SSH_PUBLIC_KEY=""
export TF_VAR_chef_repo_dir=""
export TF_VAR_gitlab_com_zone_id=""
export TF_VAR_gitlab_net_zone_id=""
export TF_VAR_gitlab_io_zone_id=""
export TF_VAR_arm_subscription_id=""
export TF_VAR_arm_tenant_id=""
export TF_VAR_arm_client_id=""
export TF_VAR_arm_client_secret=""
export TF_VAR_first_user_username=""
export TF_VAR_first_user_password=""
export TF_VAR_ssh_user=""
export TF_VAR_ssh_private_key=""
export TF_VAR_ssh_public_key=""
export TF_VAR_ssh_key=""
export STATE_S3_REGION=""
export STATE_S3_BUCKET=""
export AWS_ACCESS_KEY_ID=""
export AWS_SECRET_ACCESS_KEY=""
export STATE_S3_KEY=""
export TF_VAR_vpn_shared_secret=""
export GOOGLE_APPLICATION_CREDENTIALS=""
export TF_VAR_oauth2_client_id_prometheus=""
export TF_VAR_oauth2_client_secret_prometheus=""
export TF_VAR_oauth2_client_id_performance=""
export TF_VAR_oauth2_client_secret_performance=""
export TF_VAR_oauth2_client_id_monitoring=""
export TF_VAR_oauth2_client_secret_monitoring=""
export TF_VAR_oauth2_client_id_gitlab_ops=""
export TF_VAR_oauth2_client_secret_gitlab_ops=""
export TF_VAR_oauth2_client_id_log_proxy=""
export TF_VAR_oauth2_client_secret_log_proxy=""
export TF_VAR_oauth2_client_id_dashboards=""
export TF_VAR_oauth2_client_secret_dashboards=""
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