terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.98k stars 357 forks source link

tflint docker plugin management #2143

Closed WhiteTomX closed 1 month ago

WhiteTomX commented 1 month ago

Introduction

We are using the docker image ghcr.io/terraform-linters/tflint-bundle currently in our pipelines to check our code. This is deprecated and we should use the plugin management instead. The docker command provided automatically removes the image (and even without it) running docker run --rm -v $(pwd):/data -t ghcr.io/terraform-linters/tflint --init && docker run --rm -v $(pwd):/data -t ghcr.io/terraform-linters/tflint --recursive fails with

 Failed to run in .; exit status 1

Failed to initialize plugins; Plugin "azurerm" not found. Did you run "tflint --init"?

Proposal

I think we should state a recommended way to work with docker and plugins. My current idea is to force the plugins directory into the pwd by either creating the folder or setting it in config

config {
  plugin_dir = "./.tflint.d/plugins"
}

Another way would be to allow running init and scan in the same command. This can be archived by overwriting the entry point and running tflint via sh docker run --rm -v "$(pwd):/data" --entrypoint=/bin/sh ghcr.io/terraform-linters/tflint -c "tflint --init && tflint --recursive"

I'm not sure, what is better/should be the recommended way.

References