Skip to content

Commit

Permalink
Merge pull request #21 from devops-infra/feature/init
Browse files Browse the repository at this point in the history
Added run_init parameter to conditionally run terraform init
  • Loading branch information
ChristophShyper authored Sep 25, 2020
2 parents b1c9b6c + 9282adf commit 404550c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Main action is using [wata727](https://github.com/wata727)'s [TFLint](https://gi
| fail_on_changes | No | `true` | Whether TFLint should fail whole action. |
| tflint_config | No | `.tflint.hcl` | Location from repository root to TFLint config file. Disables `tflint_params`. |
| tflint_params | No | `` | Parameters passed to TFLint binary. See [TFLint](https://github.com/terraform-linters/tflint) for details. |

| run_init | No | `true` | Whether the action should run `terraform init`. Defaults to true. |

## Examples

Expand Down
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ author: Krzysztof Szyper / ChristophShyper / biotyk@mail.com
description: GitHub Action that will run TFlint on Terraform files
inputs:
fail_on_changes:
description: Whether action should fail if errors found. Default true
description: Whether the action should fail if errors found. Defaults totrue.
required: false
default: "true"
dir_filter:
description: Filter for directories to check. Check all by default
description: Filter for directories to check. Check all by default.
required: false
default: "*"
tflint_config:
description: Location of TFLint config file. Default .tflint.hcl
description: Location of TFLint config file. Defaults to .tflint.hcl.
required: false
default: ".tflint.hcl"
tflint_params:
description: Parameters passed to TFLint
description: Parameters passed to TFLint. Defaults to none.
required: false
default: ""
run_init:
description: Whether the action should run `terraform init`. Defaults to true.
required: false
default: "true"
runs:
using: docker
image: docker://devopsinfra/action-tflint:latest
Expand Down
12 changes: 8 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ for PREFIX in "${ARRAY[@]}"; do
cd "${WORK_DIR}/${DIRECTORY}" || RET_CODE=1
echo -e "\nDirectory: ${DIRECTORY}"
if [[ -f "${WORK_DIR}/${INPUT_TFLINT_CONFIG}" ]]; then
terraform init
if [[ "${INPUT_RUN_INIT}" == "true" ]]; then
terraform init
fi
tflint -c "${WORK_DIR}/${INPUT_TFLINT_CONFIG}" || RET_CODE=1
else
terraform init
if [[ "${INPUT_RUN_INIT}" == "true" ]]; then
terraform init
fi
tflint "${INPUT_TFLINT_PARAMS}" || RET_CODE=1
fi
cd ${WORK_DIR} || RET_CODE=1
cd "${WORK_DIR}" || RET_CODE=1
done
done

# Finish
if [[ ${RET_CODE} != "0" ]]; then
if [[ "${RET_CODE}" != "0" ]]; then
echo -e "\n[ERROR] Check log for errors."
exit 1
else
Expand Down

0 comments on commit 404550c

Please sign in to comment.