Skip to content
Snippets Groups Projects
Unverified Commit b528c184 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

feat: allow excluded directories for tflint

parent 550332ac
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -188,6 +188,7 @@ Setup process:
 
1. Ensure that a [`.tflint.hcl`](https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/config.md) file exists in the root of the project.
1. Ensure that the `GL_ASDF_TFLINT_VERSION` version for tflint is configured.
1. Directories can be excluded from tflint using the `TFLINT_EXCLUDE_REGEX` variable. See the example below.
1. The task will generate a [junit test output file](https://docs.gitlab.com/ee/ci/unit_test_reports.html) for any failed linter checks.
 
```yaml
Loading
Loading
@@ -197,6 +198,8 @@ stages:
# Not needed if .gitlab-ci-asdf-versions.yml is included...
variables:
GL_ASDF_TFLINT_VERSION: ...
# To exclude any directories, set this variable
TFLINT_EXCLUDE_REGEX: './exclude1|./exclude2'
 
include:
# Not required, but recommended
Loading
Loading
tflint:
stage: validate
needs: []
Loading
Loading
@@ -8,14 +7,13 @@ tflint:
script:
- mkdir -p "tflint-reports/"
# Find all TF files and lint the directories of those files
# See http://mywiki.wooledge.org/BashFAQ/024 for bash while subshell issue
- while read -r dir; do
- find . -type f -name '*.tf' -exec dirname {} \;|sort -u|grep -v "${TFLINT_EXCLUDE_REGEX:-__none__}" | while read -r dir; do
junit_file="$(echo "$dir"|sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g).xml";
tflint -c ".tflint.hcl" --init "${dir}";
tflint -c ".tflint.hcl" "${dir}" -f compact || failed=1;
tflint -c ".tflint.hcl" "${dir}" -f junit > "tflint-reports/${junit_file}" || failed=1;
done < <(find . -type f -name '*.tf' -exec dirname {} \;|sort -u);
if [ "${failed}" == "1" ]; then exit 1; fi
tflint -c ".tflint.hcl" "${dir}" -f compact || touch tflint-reports/failed;
tflint -c ".tflint.hcl" "${dir}" -f junit > "tflint-reports/${junit_file}" || touch tflint-reports/failed;
done;
if [ -f "tflint-reports/failed" ]; then exit 1; fi
artifacts:
when: always
reports:
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment