Created
October 9, 2020 19:11
-
-
Save devdrops/5b367b52542787af66e9e48a5c389a53 to your computer and use it in GitHub Desktop.
Revisions
-
devdrops created this gist
Oct 9, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ # TF Diff - Checando diferenças nos arquivos terraform Trabalha com [Terraform](https://www.terraform.io/)? Costuma reforçar o uso de `terraform fmt` nos Pull Requests do seu time? Cansou de validar se os arquivos do Pull Request seguem corretamenta a sintaxe?  **SEUS PROBLEMAS ACABARAM!** Esse script em bash, ao ser executado, valida quais arquivos foram adicionados e/ou modificados, dizendo quais devem ser verificados. ### Requisitos - Docker - Bash - Git This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ #!/bin/bash echo "" echo " ======================================================================== " echo " : ████████ ███████ ██████ ██ ███████ ███████ : " echo " : ██ ██ ██ ██ ██ ██ ██ : " echo " : ██ █████ ██ ██ ██ █████ █████ : " echo " : ██ ██ ██ ██ ██ ██ ██ : " echo " : ██ ██ ██████ ██ ██ ██ : " echo " ======================================================================== " echo "" echo " Check differences with terraform fmt on all changed .tf files." echo "" echo "" LIST=./list.txt if [[ -z "${BASE_BRANCH}" ]]; then export BASE_BRANCH="master" fi if [[ -z "${TF_VERSION}" ]]; then export TF_VERSION="0.11.14" fi echo " === Upgrading repository references ====================================>" echo "" git fetch --all > /dev/null 2>&1 git diff origin/$BASE_BRANCH...$1 --name-only --diff-filter=AM | grep .tf > "$LIST" echo " === Target Branch: $1" echo " === Base Branch: $BASE_BRANCH" echo " === Terraform Version: $TF_VERSION" echo " === Files to check:" cat "$LIST" echo "" echo " === Checking files =====================================================>" while IFS= read -r file; do docker run --rm -v $(pwd):/code -w /code hashicorp/terraform:${TF_VERSION} fmt -check=true -list=false ./"$file" if [ $? = 0 ]; then printf " = OK: $file\n" else printf " = FAILED: $file\n" break fi done < "$LIST" rm "$LIST" echo "" echo " === Done! ==============================================================>" echo ""