Created
April 10, 2024 13:53
-
-
Save egorksv/65ab1a1ab8bc5cfdb7b3a6330e90b5af to your computer and use it in GitHub Desktop.
Terragrunt shell script to get layered deployments
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
#!/bin/bash | |
ENVS=("staging" "production") | |
CMD=("plan" "apply" "destroy" "init") | |
MGROUPS=("vpc" "eks" "eks-apps") | |
env=$1 | |
cmd=$2 | |
group=$3 | |
args=${@:4} | |
if [[ ! $(echo ${MGROUPS[@]} | fgrep -w $group) ]] | |
then | |
unset group | |
args=${@:3} | |
fi | |
echo "args: '$args' group: '$group'" | |
TG_PARAMS="" | |
echo "Checking if all required arguments are provided" | |
if [[ -z $env ]] || [[ -z $cmd ]] | |
then | |
echo "Usage: tg.sh <env> <cmd> [group] [args]" | |
exit 1 | |
fi | |
if [[ ! $(echo ${ENVS[@]} | fgrep -w $env) ]] | |
then | |
echo "Environment $env not found" | |
exit 1 | |
fi | |
if [[ ! $(echo ${CMD[@]} | fgrep -w $cmd) ]] | |
then | |
echo "Command $cmd not found" | |
exit 1 | |
fi | |
if [[ ! -z $group ]] && [[ $(echo ${MGROUPS[@]} | fgrep -w $group) ]] | |
then | |
TG_PARAMS="$TG_PARAMS --terragrunt-modules-that-include terragrunt/_group/$group.hcl" | |
fi | |
echo "Running Terragrunt $cmd for group $group in environment $env with args $args" | |
set -x | |
TG_ENV=$env terragrunt run-all $cmd \ | |
$TG_PARAMS \ | |
--terragrunt-strict-include \ | |
--terragrunt-include-dir "./terragrunt/_env" \ | |
--terragrunt-include-dir "./terragrunt/_group" \ | |
--terragrunt-include-dir "./terragrunt/$env/*" \ | |
$args | |
#terragrunt run-all $cmd \ | |
# --terragrunt-ignore-dependency-order \ | |
# --terragrunt-strict-include \ | |
# --terragrunt-ignore-external-dependencies \ | |
# $args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment