Skip to content

Commit d4ab109

Browse files
committed
README.md, src/main.sh, test/local-test.sh: Support for 'run-all' options
1. test/local-test.sh: Added script to run local testing 2. README.md: Updated about local testing
1 parent 259fc9e commit d4ab109

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,17 @@ The usual [Terraform environment variables](https://www.terraform.io/docs/comman
126126

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

129+
130+
## Testing
131+
132+
If you want to test these scripts locally, its possible after installing docker in your test environment
133+
134+
1. Open `test/local-test.sh` and modify the GLOBAL variables (in caps) according to your needs
135+
2. Run it with: `test/local-test.sh` or `test/local-test.sh run-all plan`
136+
3. The above command:
137+
- Builds a docker container with image tag `tg`
138+
- Starts that container with those global variables
139+
140+
141+
129142
**This is a fork of [Terraform Github Actions](https://github.com/hashicorp/terraform-github-actions).**

src/main.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ function parseInputs {
3232
fi
3333

3434
if [ "${INPUT_TF_ACTIONS_SUBCOMMAND}" != "" ]; then
35-
tfSubcommand=${INPUT_TF_ACTIONS_SUBCOMMAND}
35+
if [[ "${INPUT_TF_ACTIONS_SUBCOMMAND}" = run-all* ]]; then
36+
tfSubcommand=$(echo $INPUT_TF_ACTIONS_SUBCOMMAND|cut -d ' ' -f 2 )
37+
else
38+
tfSubcommand=${INPUT_TF_ACTIONS_SUBCOMMAND}
39+
fi
3640
else
3741
echo "Input terraform_subcommand cannot be empty"
3842
exit 1

test/local-test.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# This is a script for easily running the local testing
4+
# Comes very handy in local development
5+
6+
TF_VERSION='0.14.6'
7+
TG_VERSION='v0.28.4'
8+
TF_WORKING_DIR='/var/opt'
9+
TF_SUBCOMMAND='run-all init'
10+
TG_LOCAL_WORK_DIR="$(pwd)" # TODO, provide some path which has the terragrunt code
11+
12+
function build_docker {
13+
echo "INFO: Building docker image"
14+
docker build -t tg .
15+
}
16+
17+
function run_docker {
18+
echo "INFO: Test running docker"
19+
docker run -it \
20+
-e INPUT_TF_ACTIONS_VERSION=$TF_VERSION \
21+
-e INPUT_TG_ACTIONS_VERSION=$TG_VERSION \
22+
-e INPUT_TF_ACTIONS_SUBCOMMAND="$TF_SUBCOMMAND" \
23+
-e INPUT_TF_ACTIONS_WORKING_DIR="$TF_WORKING_DIR" \
24+
-v $TG_LOCAL_WORK_DIR:$TF_WORKING_DIR \
25+
tg
26+
}
27+
28+
function main {
29+
30+
# validate cli
31+
if [ "$1" != "" ];then
32+
TF_SUBCOMMAND=$*
33+
fi
34+
35+
# Build the image
36+
build_docker
37+
38+
# test run it
39+
run_docker
40+
}
41+
42+
main $*

0 commit comments

Comments
 (0)