feat: add support for Terraform modules in tflint (#2297)

* fix: support tflint relative module references

* chore: add test for relative module imports

* chore: add terraform binary

* chore: move tests

* chore: add newlines to tests

* chore: add newlines to tests

* refactor: move terraform get

* refactor: put terraform get back where it was

Co-authored-by: Lukas Gravley <admiralawkbar@github.com>
This commit is contained in:
Colwyn Fritze-Moor 2022-01-06 09:04:10 -08:00 committed by GitHub
parent 9434520fdf
commit 09b571b1b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,10 @@
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "2.11.1"
bucket = "test-bucket"
}
module "good_relative_reference" {
source = "../modules/ec2_instance"
}

View file

@ -0,0 +1,14 @@
resource "aws_instance" "good" {
ami = "ami-0ff8a91507f77f867"
instance_type = "t2.small"
associate_public_ip_address = false
vpc_security_group_ids = ["sg-12345678901234567"]
metadata_options {
http_endpoint = "disabled"
}
ebs_block_device {
encrypted = true
}
}

View file

@ -14,6 +14,7 @@ FROM yoheimuta/protolint:v0.35.2 as protolint
FROM golangci/golangci-lint:v1.43.0 as golangci-lint FROM golangci/golangci-lint:v1.43.0 as golangci-lint
FROM koalaman/shellcheck:v0.8.0 as shellcheck FROM koalaman/shellcheck:v0.8.0 as shellcheck
FROM ghcr.io/terraform-linters/tflint-bundle:v0.34.1.1 as tflint FROM ghcr.io/terraform-linters/tflint-bundle:v0.34.1.1 as tflint
FROM hashicorp/terraform:1.1.2 as terraform
FROM alpine/terragrunt:1.1.2 as terragrunt FROM alpine/terragrunt:1.1.2 as terragrunt
FROM mvdan/shfmt:v3.4.2 as shfmt FROM mvdan/shfmt:v3.4.2 as shfmt
FROM accurics/terrascan:1.13.0 as terrascan FROM accurics/terrascan:1.13.0 as terrascan
@ -129,6 +130,11 @@ COPY --from=shellcheck /bin/shellcheck /usr/bin/
##################### #####################
COPY --from=golangci-lint /usr/bin/golangci-lint /usr/bin/ COPY --from=golangci-lint /usr/bin/golangci-lint /usr/bin/
#####################
# Install Terraform #
#####################
COPY --from=terraform /bin/terraform /usr/bin/
################## ##################
# Install TFLint # # Install TFLint #
################## ##################

View file

@ -257,6 +257,15 @@ function LintCodebase() {
cd "${DIR_NAME}" || exit cd "${DIR_NAME}" || exit
${LINTER_COMMAND} "${FILE_NAME}" 2>&1 ${LINTER_COMMAND} "${FILE_NAME}" 2>&1
) )
############################################################################################
# Corner case for TERRAFORM_TFLINT as it cant use the full path and needs to fetch modules #
############################################################################################
elif [[ ${FILE_TYPE} == "TERRAFORM_TFLINT" ]]; then
LINT_CMD=$(
cd "${DIR_NAME}" || exit
terraform get 2>&1
${LINTER_COMMAND} "${FILE_NAME}" 2>&1
)
else else
################################ ################################
# Lint the file with the rules # # Lint the file with the rules #