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

Move the workflow scripts to where they're used #632

Merged
merged 2 commits into from
Feb 4, 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
64 changes: 64 additions & 0 deletions .github/workflows/validate-terraform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# Validates and lints Terraform for 1:M directories, exiting if any errors are produced

program_log () {
echo "${0}: ${1}"
}

error_log () {
echo "Error: ${1}"
}

# check for Terraform
if ! command -v terraform &> /dev/null; then
error_log "Terraform could not be found. This script requires the Terraform CLI."
echo "See https://learn.hashicorp.com/tutorials/terraform/install-cli for installation instructions."
exit 1
fi

# validate Terraform with `terraform validate`
validate() {
local tf_dir=$1
cd "${tf_dir}" || exit 1
program_log "validating at ${tf_dir}..."
terraform init -backend=false >> /dev/null || exit 1
terraform validate >> /dev/null || exit 1
program_log "successful validation with \"terraform validate ${tf_dir}\"!"
}

# check Terraform formatting with `terraform fmt`
check_formatting() {
local tf_dir=$1
cd "${tf_dir}" || exit 1
program_log "checking formatting at ${tf_dir}..."
if terraform fmt -check -recursive >> /dev/null;
then
program_log "successful check with \"terraform fmt -check -recursive ${tf_dir}\""
else
linting_results=$(terraform fmt -check -recursive)
for j in $linting_results
do
error_log "\"${j}\" is not formatted correctly. Format with the command \"terraform fmt ${j}\""
done
program_log "run \"terraform fmt -recursive\" to format all Terraform components in a directory"
exit 1
fi
}

# get the starting directory
working_dir=$(pwd)

# for every argument, try to validate and check formatting
for arg in "$@"
do
real_path=$(realpath "${arg}")
validate "${real_path}"
check_formatting "${real_path}"
cd "${working_dir}" || exit 1
done

program_log "done!"
10 changes: 3 additions & 7 deletions .github/workflows/validate-terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# Licensed under the MIT License.

name: validate-terraform
on:
on:
pull_request:
branches: [main]
paths:
paths:
- 'src/terraform/**'
- '!src/terraform/**.md'
workflow_dispatch:
Expand All @@ -24,8 +24,4 @@ jobs:
- shell: bash
name: validate and lint terraform
run: |
src/build/validate_tf.sh src/terraform/mlz src/terraform/tier3
- shell: bash
name: check terraform formatting
run: |
src/build/check_tf_format.sh src/terraform
.github/workflows/validate-terraform.sh src/terraform/mlz src/terraform/tier3
49 changes: 0 additions & 49 deletions src/build/check_tf_format.sh

This file was deleted.

25 changes: 0 additions & 25 deletions src/build/delete.sh

This file was deleted.

39 changes: 0 additions & 39 deletions src/build/validate_tf.sh

This file was deleted.