Running TFLint through their Docker Image Here – I have to pass tflint multiple commands one after the other to initialize and run the tool which is where I’m running into issues
I have ran it locally using the following commands, which returns what I want:
tflint --init --config 'path/to/config/'
tflint --config 'path/to/config/config.tflint.hcl' 'path/to/terraform/code'
# AND
tflint --init --config 'path/to/config/config.tflint.hcl' && tflint --config 'path/to/config/' 'path/to/terraform/code'
Here are the commands I use to run the docker image:
docker run -it -v "$(pwd):/tflint" ghcr.io/terraform-linters/tflint --init --config '/tflint/path/to/config/config.tflint.hcl'
docker run -it -v "$(pwd):/tflint" ghcr.io/terraform-linters/tflint --config '/tflint/path/to/config/config.tflint.hcl' '/tflint/path/to/terraform/code'
Which outputs:
Installing `azurerm` plugin...
Installed `azurerm` (source: github.com/terraform-linters/tflint-ruleset-azurerm, version: 0.15.0)
Failed to initialize plugins; Plugin `azurerm` not found. Did you run `tflint --init`?
I know this is creating a new container on each run which is why it’s not detecting its been initialized already – My question is how can I reuse this container to pass the extra args it requires after initializing it? Or is there a better way of doing so? Any input/feedback would be appreciated 🙂 Thank you!
Note: Here is the Dockerfile TFLint uses
FROM golang:1.18.1-alpine3.15 as builder
RUN apk add --no-cache make
WORKDIR /tflint
COPY . /tflint
RUN make build
FROM alpine:3.15.4 as prod
LABEL maintainer=terraform-linters
RUN apk add --no-cache ca-certificates
COPY --from=builder /tflint/dist/tflint /usr/local/bin
ENTRYPOINT ["tflint"]
WORKDIR /data
2
Answers
You can create your dedicated Dockerfile that uses the tflint base image
ghcr.io/terraform-linters/tflint
and copy your files.Something like:
It is just an example to give you an idea. Then you build it locally:
docker build -t mytflint .
And use your built image:
docker run mytflint ......
You can change entrypoint to
sh
and pass multiple commandsdocker run -it -v "$(pwd):/tflint" --entrypoint=/bin/sh ghcr.io/terraform-linters/tflint -c "tflint --init --config '/tflint/path/to/config/config.tflint.hcl'; tflint --config '/tflint/path/to/config/config.tflint.hcl' '/tflint/path/to/terraform/code'"