Skip to content

Commit 0dacfa8

Browse files
committedApr 21, 2020
Allow to choose to run commands with terraform or terraform
1 parent 7a77dae commit 0dacfa8

12 files changed

+28
-17
lines changed
 

‎README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ jobs:
3232
- name: 'Terragrunt Format'
3333
uses: the-commons-project/terragrunt-github-actions@master
3434
with:
35-
tf_actions_actions_version: ${{ env.tf_version }}
36-
tg_actions_actions_version: ${{ env.tg_version }}
37-
tf_actions_actions_subcommand: 'fmt'
38-
tf_actions_actions_working_dir: ${{ env.tf_working_dir }}
39-
tf_actions_actions_comment: true
35+
tf_actions_version: ${{ env.tf_version }}
36+
tg_actions_version: ${{ env.tg_version }}
37+
tf_actions_binary: 'terraform'
38+
tf_actions_subcommand: 'fmt'
39+
tf_actions_working_dir: ${{ env.tf_working_dir }}
40+
tf_actions_comment: true
4041
env:
4142
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4243
- name: 'Terragrunt Init'
@@ -54,6 +55,7 @@ jobs:
5455
with:
5556
tf_actions_version: ${{ env.tf_version }}
5657
tg_actions_version: ${{ env.tg_version }}
58+
tf_actions_binary: 'terraform'
5759
tf_actions_subcommand: 'validate'
5860
tf_actions_working_dir: ${{ env.tf_working_dir }}
5961
tf_actions_comment: true
@@ -80,6 +82,7 @@ Inputs configure Terraform GitHub Actions to perform different actions.
8082
| Input Name | Description | Required |
8183
|:------------------------------------|:-----------------------------------------------------------|:--------:|
8284
| tf_actions_subcommand | The Terraform/Terragrunt subcommand to execute. | `Yes` |
85+
| tf_actions_binary | The binary to run the commands with | `No` |
8386
| tf_actions_version | The Terraform version to install and execute. If set to `latest`, the latest stable version will be used. | `Yes` |
8487
| tg_actions_version | The Terragrunt version to install and execute. If set to `latest`, the latest stable version will be used. | `Yes` |
8588
| tf_actions_cli_credentials_hostname | Hostname for the CLI credentials file. Defaults to `app.terraform.io`. | `No` |

‎action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
tf_actions_subcommand:
99
description: 'Terraform or Terragrunt subcommand to execute.'
1010
required: true
11+
tf_actions_binary:
12+
description: 'Binary to use. Terraform or Terragrunt'
13+
default: 'terragrunt'
1114
tf_actions_version:
1215
description: 'Terraform version to install.'
1316
required: true

‎src/main.sh

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ function parseInputs {
4444
tfWorkingDir=${INPUT_TF_ACTIONS_WORKING_DIR}
4545
fi
4646

47+
tfBinary="terragrunt"
48+
if [[ -n "${INPUT_TF_ACTIONS_BINARY}" ]]; then
49+
tfBinary=${INPUT_TF_ACTIONS_BINARY}
50+
fi
51+
4752
tfComment=0
4853
if [ "${INPUT_TF_ACTIONS_COMMENT}" == "1" ] || [ "${INPUT_TF_ACTIONS_COMMENT}" == "true" ]; then
4954
tfComment=1

‎src/terragrunt_apply.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntApply {
44
# Gather the output of `terragrunt apply`.
55
echo "apply: info: applying Terragrunt configuration in ${tfWorkingDir}"
6-
applyOutput=$(terragrunt apply -auto-approve -input=false ${*} 2>&1)
6+
applyOutput=$(${tfBinary} apply -auto-approve -input=false ${*} 2>&1)
77
applyExitCode=${?}
88
applyCommentStatus="Failed"
99

‎src/terragrunt_destroy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntDestroy {
44
# Gather the output of `terragrunt destroy`.
55
echo "destroy: info: destroying Terragrunt-managed infrastructure in ${tfWorkingDir}"
6-
destroyOutput=$(terragrunt destroy -auto-approve -input=false ${*} 2>&1)
6+
destroyOutput=$(${tfBinary} destroy -auto-approve -input=false ${*} 2>&1)
77
destroyExitCode=${?}
88
destroyCommentStatus="Failed"
99

‎src/terragrunt_fmt.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function terragruntFmt {
99

1010
# Gather the output of `terragrunt fmt`.
1111
echo "fmt: info: checking if Terragrunt files in ${tfWorkingDir} are correctly formatted"
12-
fmtOutput=$(terragrunt fmt -check=true -write=false -diff ${fmtRecursive} ${*} 2>&1)
12+
fmtOutput=$(${tfBinary} fmt -check=true -write=false -diff ${fmtRecursive} ${*} 2>&1)
1313
fmtExitCode=${?}
1414

1515
# Exit code of 0 indicates success. Print the output and exit.
@@ -29,19 +29,19 @@ function terragruntFmt {
2929
fi
3030

3131
# Exit code of !0 and !2 indicates failure.
32-
echo "fmt: error: Terraform files in ${tfWorkingDir} are incorrectly formatted"
32+
echo "fmt: error: Terragrunt files in ${tfWorkingDir} are incorrectly formatted"
3333
echo "${fmtOutput}"
3434
echo
3535
echo "fmt: error: the following files in ${tfWorkingDir} are incorrectly formatted"
36-
fmtFileList=$(terraform fmt -check=true -write=false -list ${fmtRecursive})
36+
fmtFileList=$(${tfBinary} fmt -check=true -write=false -list ${fmtRecursive})
3737
echo "${fmtFileList}"
3838
echo
3939

4040
# Comment on the pull request if necessary.
4141
if [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "${tfComment}" == "1" ]; then
4242
fmtComment=""
4343
for file in ${fmtFileList}; do
44-
fmtFileDiff=$(terraform fmt -check=true -write=false -diff "${file}" | sed -n '/@@.*/,//{/@@.*/d;p}')
44+
fmtFileDiff=$(${tfBinary} fmt -check=true -write=false -diff "${file}" | sed -n '/@@.*/,//{/@@.*/d;p}')
4545
fmtComment="${fmtComment}
4646
<details><summary><code>${tfWorkingDir}/${file}</code></summary>
4747

‎src/terragrunt_import.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntImport {
44
# Gather the output of `terragrunt import`.
55
echo "import: info: importing Terragrunt configuration in ${tfWorkingDir}"
6-
importOutput=$(terragrunt import -input=false ${*} 2>&1)
6+
importOutput=$(${tfBinary} import -input=false ${*} 2>&1)
77
importExitCode=${?}
88
importCommentStatus="Failed"
99

‎src/terragrunt_init.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntInit {
44
# Gather the output of `terragrunt init`.
55
echo "init: info: initializing Terragrunt configuration in ${tfWorkingDir}"
6-
initOutput=$(terragrunt init -input=false ${*} 2>&1)
6+
initOutput=$(${tfBinary} init -input=false ${*} 2>&1)
77
initExitCode=${?}
88

99
# Exit code of 0 indicates success. Print the output and exit.

‎src/terragrunt_output.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntOutput {
44
# Gather the output of `terragrunt output`.
55
echo "output: info: gathering all the outputs for the Terragrunt configuration in ${tfWorkingDir}"
6-
outputOutput=$(terragrunt output -json ${*} 2>&1)
6+
outputOutput=$(${tfBinary} output -json ${*} 2>&1)
77
outputExitCode=${?}
88

99
# Exit code of 0 indicates success. Print the output and exit.

‎src/terragrunt_plan.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntPlan {
44
# Gather the output of `terragrunt plan`.
55
echo "plan: info: planning Terragrunt configuration in ${tfWorkingDir}"
6-
planOutput=$(terragrunt plan -detailed-exitcode -input=false ${*} 2>&1)
6+
planOutput=$(${tfBinary} plan -detailed-exitcode -input=false ${*} 2>&1)
77
planExitCode=${?}
88
planHasChanges=false
99
planCommentStatus="Failed"

‎src/terragrunt_taint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function terragruntTaint {
44
# Gather the output of `terragrunt taint`.
55
echo "taint: info: tainting terragrunt configuration in ${tfWorkingDir}"
66
#taintOutput=$(terragrunt taint ${*} 2>&1)
7-
taintOutput=$(for resource in ${*}; do terragrunt taint -allow-missing $resource; done 2>&1)
7+
taintOutput=$(for resource in ${*}; do ${tfBinary} taint -allow-missing $resource; done 2>&1)
88
taintExitCode=${?}
99
taintCommentStatus="Failed"
1010

‎src/terragrunt_validate.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function terragruntValidate {
44
# Gather the output of `terragrunt validate`.
55
echo "validate: info: validating Terragrunt configuration in ${tfWorkingDir}"
6-
validateOutput=$(terragrunt validate ${*} 2>&1)
6+
validateOutput=$(${tfBinary} validate ${*} 2>&1)
77
validateExitCode=${?}
88

99
# Exit code of 0 indicates success. Print the output and exit.

0 commit comments

Comments
 (0)
Please sign in to comment.