-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afb402b
commit 32b3d5b
Showing
11 changed files
with
179 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Build 🛠️ | ||
on: | ||
pull_request: | ||
push: | ||
# tags: | ||
# - '*' | ||
branches: | ||
- '*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build: | ||
name: Go build 🚀 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup-go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' | ||
cache: false | ||
|
||
- name: security | ||
uses: securego/gosec@master | ||
with: | ||
args: -exclude=G104,G204,G107 ./... |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
lint: | ||
name: Lint 🚀 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup-go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' | ||
cache: false | ||
|
||
- name: lint | ||
uses: golangci/golangci-lint-action@v5 | ||
with: | ||
version: latest |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# There are not tests, but... just prepare the pipeline for the future | ||
name: Test | ||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
test: | ||
name: Test 🚀 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: setup-go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' | ||
cache: false | ||
|
||
- name: test | ||
run: go test -v ./... |
This file contains 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 characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
echo -en "\e[32m> Starting tfsum...\e[0m\n" | ||
|
||
# Default variables | ||
tf_command="terraform" | ||
tf_action="plan" | ||
tf_params='-parallelism=100' | ||
|
||
# Function to display help text | ||
usage() { | ||
echo "Usage: $0 [-c] [-a] [-p] [-h]" | ||
echo "Options:" | ||
echo " -c Command. Execute terragrunt or terraform. (Required)" | ||
echo " -a Action. Execute plan, apply or destroy. (Optional)(Default: plan)" | ||
echo " -p Params. Terraform params like: -auto-approve, -parallelism ...etc. (Optional)(Default: -parallelism=100)" | ||
echo " -h Display the help message" | ||
echo -en "\e[32m> Example: $ tfsum -c terraform -a plan -p '-parallelism=50 -no-color'\e[0m\n" | ||
} | ||
|
||
# Parse options using getopts | ||
while getopts "c:a:p:h" option; do | ||
case "${option}" in | ||
c) # Set command | ||
tf_command=${OPTARG} | ||
if [ "${OPTARG}" != "terraform" ] && [ "${OPTARG}" != "terragrunt" ]; then | ||
echo -en "\e[31m> Invalid command ${OPTARG}. Supported commands are: terraform, terragrunt\e[0m\n" | ||
exit 1 | ||
fi | ||
;; | ||
a) # Set action | ||
tf_action=${OPTARG} | ||
if [ "${OPTARG}" != "plan" ] && [ "${OPTARG}" != "apply" ] && [ "${OPTARG}" != "delete" ]; then | ||
echo -en "\e[31m> Invalid command. Supported commands are: plan, apply, delete\e[0m\n" | ||
exit 1 | ||
fi | ||
;; | ||
p) # Terraform params | ||
tf_params="${OPTARG//\'/}" | ||
;; | ||
h) # Help option | ||
usage | ||
exit 0 | ||
;; | ||
\?) # Invalid option | ||
echo "Invalid option: -${OPTARG}" | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
|
||
# If no flags, print usage | ||
if [ $# -eq 0 ]; then | ||
echo -en "\e[31m> You should type \$ tfsum -c terraform/terragrunt at least.\e[0m\n" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
# Start program | ||
echo -en "\e[32m> Executing $tf_command $tf_action $tf_params\e[0m\n" | ||
if [ "$tf_action" == "plan" ]; then | ||
tf_params+=" -out plan.tfplan" | ||
# shellcheck disable=SC2086 | ||
$tf_command "$tf_action" $tf_params | ||
# Print summarized plan | ||
$tf_command show -json plan.tfplan | tftools summarize --show-tags | ||
else | ||
# shellcheck disable=SC2086 | ||
$tf_command "$tf_action" $tf_params | ||
fi |