Skip to content

Commit 404550c

Browse files
Merge pull request #21 from devops-infra/feature/init
Added run_init parameter to conditionally run terraform init
2 parents b1c9b6c + 9282adf commit 404550c

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Main action is using [wata727](https://github.com/wata727)'s [TFLint](https://gi
4545
| fail_on_changes | No | `true` | Whether TFLint should fail whole action. |
4646
| tflint_config | No | `.tflint.hcl` | Location from repository root to TFLint config file. Disables `tflint_params`. |
4747
| tflint_params | No | `` | Parameters passed to TFLint binary. See [TFLint](https://github.com/terraform-linters/tflint) for details. |
48-
48+
| run_init | No | `true` | Whether the action should run `terraform init`. Defaults to true. |
4949

5050
## Examples
5151

action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ author: Krzysztof Szyper / ChristophShyper / biotyk@mail.com
33
description: GitHub Action that will run TFlint on Terraform files
44
inputs:
55
fail_on_changes:
6-
description: Whether action should fail if errors found. Default true
6+
description: Whether the action should fail if errors found. Defaults totrue.
77
required: false
88
default: "true"
99
dir_filter:
10-
description: Filter for directories to check. Check all by default
10+
description: Filter for directories to check. Check all by default.
1111
required: false
1212
default: "*"
1313
tflint_config:
14-
description: Location of TFLint config file. Default .tflint.hcl
14+
description: Location of TFLint config file. Defaults to .tflint.hcl.
1515
required: false
1616
default: ".tflint.hcl"
1717
tflint_params:
18-
description: Parameters passed to TFLint
18+
description: Parameters passed to TFLint. Defaults to none.
1919
required: false
2020
default: ""
21+
run_init:
22+
description: Whether the action should run `terraform init`. Defaults to true.
23+
required: false
24+
default: "true"
2125
runs:
2226
using: docker
2327
image: docker://devopsinfra/action-tflint:latest

entrypoint.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ for PREFIX in "${ARRAY[@]}"; do
1616
cd "${WORK_DIR}/${DIRECTORY}" || RET_CODE=1
1717
echo -e "\nDirectory: ${DIRECTORY}"
1818
if [[ -f "${WORK_DIR}/${INPUT_TFLINT_CONFIG}" ]]; then
19-
terraform init
19+
if [[ "${INPUT_RUN_INIT}" == "true" ]]; then
20+
terraform init
21+
fi
2022
tflint -c "${WORK_DIR}/${INPUT_TFLINT_CONFIG}" || RET_CODE=1
2123
else
22-
terraform init
24+
if [[ "${INPUT_RUN_INIT}" == "true" ]]; then
25+
terraform init
26+
fi
2327
tflint "${INPUT_TFLINT_PARAMS}" || RET_CODE=1
2428
fi
25-
cd ${WORK_DIR} || RET_CODE=1
29+
cd "${WORK_DIR}" || RET_CODE=1
2630
done
2731
done
2832

2933
# Finish
30-
if [[ ${RET_CODE} != "0" ]]; then
34+
if [[ "${RET_CODE}" != "0" ]]; then
3135
echo -e "\n[ERROR] Check log for errors."
3236
exit 1
3337
else

0 commit comments

Comments
 (0)