如何运行TFLint Docker语言 - 传递多个参数



通过Docker Image运行TFLint这里-我必须一个接一个地传递TFLint多个命令来初始化和运行工具,这就是我遇到问题的地方

我已经使用以下命令在本地运行了它,它返回了我想要的结果:

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'
以下是我用来运行docker镜像的命令:

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'

输出:

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`?

我知道这是在每次运行时创建一个新的容器,这就是为什么它没有检测到它已经初始化-我的问题是我如何重用这个容器来传递初始化后所需的额外参数?还是有更好的方法?任何输入/反馈将不胜感激:)谢谢!

注意:这是TFLint使用的Dockerfile

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

您可以将入口点更改为sh并传递多个命令

docker 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'"

您可以创建您的专用Dockerfile,使用tflint基础映像ghcr.io/terraform-linters/tflint并复制您的文件。比如:

FROM ghcr.io/terraform-linters/tflint
COPY <my files>
RUN tflint --init .......

这只是一个例子给你一个想法。然后在本地构建:

docker build -t mytflint .

并使用您的构建映像:

docker run mytflint ......

最新更新