Skip to content

Commit

Permalink
README.md, src/main.sh, test/local-test.sh: Support for 'run-all' opt…
Browse files Browse the repository at this point in the history
…ions

1. test/local-test.sh: Added script to run local testing
2. README.md: Updated about local testing
  • Loading branch information
maniankara committed Feb 24, 2021
1 parent 259fc9e commit d4ab109
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,17 @@ The usual [Terraform environment variables](https://www.terraform.io/docs/comman

Other environment variables may be configured to pass data into Terraform. If the data is sensitive, consider using [secrets](#secrets) instead.


## Testing

If you want to test these scripts locally, its possible after installing docker in your test environment

1. Open `test/local-test.sh` and modify the GLOBAL variables (in caps) according to your needs
2. Run it with: `test/local-test.sh` or `test/local-test.sh run-all plan`
3. The above command:
- Builds a docker container with image tag `tg`
- Starts that container with those global variables



**This is a fork of [Terraform Github Actions](https://github.com/hashicorp/terraform-github-actions).**
6 changes: 5 additions & 1 deletion src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function parseInputs {
fi

if [ "${INPUT_TF_ACTIONS_SUBCOMMAND}" != "" ]; then
tfSubcommand=${INPUT_TF_ACTIONS_SUBCOMMAND}
if [[ "${INPUT_TF_ACTIONS_SUBCOMMAND}" = run-all* ]]; then
tfSubcommand=$(echo $INPUT_TF_ACTIONS_SUBCOMMAND|cut -d ' ' -f 2 )
else
tfSubcommand=${INPUT_TF_ACTIONS_SUBCOMMAND}
fi
else
echo "Input terraform_subcommand cannot be empty"
exit 1
Expand Down
42 changes: 42 additions & 0 deletions test/local-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# This is a script for easily running the local testing
# Comes very handy in local development

TF_VERSION='0.14.6'
TG_VERSION='v0.28.4'
TF_WORKING_DIR='/var/opt'
TF_SUBCOMMAND='run-all init'
TG_LOCAL_WORK_DIR="$(pwd)" # TODO, provide some path which has the terragrunt code

function build_docker {
echo "INFO: Building docker image"
docker build -t tg .
}

function run_docker {
echo "INFO: Test running docker"
docker run -it \
-e INPUT_TF_ACTIONS_VERSION=$TF_VERSION \
-e INPUT_TG_ACTIONS_VERSION=$TG_VERSION \
-e INPUT_TF_ACTIONS_SUBCOMMAND="$TF_SUBCOMMAND" \
-e INPUT_TF_ACTIONS_WORKING_DIR="$TF_WORKING_DIR" \
-v $TG_LOCAL_WORK_DIR:$TF_WORKING_DIR \
tg
}

function main {

# validate cli
if [ "$1" != "" ];then
TF_SUBCOMMAND=$*
fi

# Build the image
build_docker

# test run it
run_docker
}

main $*

0 comments on commit d4ab109

Please sign in to comment.