Skip to content

README.md, src/main.sh, test/local-test.sh: Support for 'run-all' options #5

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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
37 changes: 37 additions & 0 deletions test/local-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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 plan'
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 {

# Build the image
build_docker

# test run it
run_docker "$*"
}

main "$*"