如何抑制/忽略 tflint 警告
我第一次使用 tflint 扫描我的 terraform 代码。为此,我创建了 shell 脚本来执行 tflint 命令,但是,在执行 tflint 作业时,我收到一些 [WARN] 消息。我不确定它们是如何生成的。有办法抑制吗?
tflint 命令已成功执行,并且还在我的 terraform 代码中显示可能的问题/通知。
我正在使用下面的 Github 工作流程操作;
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v1
with:
tflint_version: v0.26.0
- name: Lint Terraform Code
run: scripts/tflint.sh
shell: bash
continue-on-error: false
“.tflint.hcl”文件 ->
plugin "aws" {
enabled = true
version = "0.12.0"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}
rule "terraform_naming_convention" {
enabled = true
}
rule "terraform_unused_declarations" {
enabled = true
}
rule "terraform_deprecated_index" {
enabled = true
}
rule "terraform_documented_outputs" {
enabled = true
}
rule "terraform_documented_variables" {
enabled = true
}
rule "terraform_typed_variables" {
enabled = true
}
tflint.sh->
#!/usr/bin/env bash
echo "Scanning all files(*.tf) with tflint"
find * -name '*.tf' | grep -E -v ".terraform|.terragrunt-cache" | while read -r line; do
tflint "$line" -f compact
done
显示 [WARN] 消息的 Github 工作流输出 -->
I am using tflint for the first time to scan my terraform code. For that I have created shell script to execute tflint command however, I am getting some [WARN] messages when tflint job is executed. I am not sure how they are generated. Is there a way to suppress it?
tflint command is getting executed successfully and also showing possible issues/notice in my terraform code.
I am using below Github workflow action;
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v1
with:
tflint_version: v0.26.0
- name: Lint Terraform Code
run: scripts/tflint.sh
shell: bash
continue-on-error: false
".tflint.hcl" file ->
plugin "aws" {
enabled = true
version = "0.12.0"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}
rule "terraform_naming_convention" {
enabled = true
}
rule "terraform_unused_declarations" {
enabled = true
}
rule "terraform_deprecated_index" {
enabled = true
}
rule "terraform_documented_outputs" {
enabled = true
}
rule "terraform_documented_variables" {
enabled = true
}
rule "terraform_typed_variables" {
enabled = true
}
tflint.sh ->
#!/usr/bin/env bash
echo "Scanning all files(*.tf) with tflint"
find * -name '*.tf' | grep -E -v ".terraform|.terragrunt-cache" | while read -r line; do
tflint "$line" -f compact
done
Github workflow output showing [WARN] messages-->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从 tflint
v0.39.3
参考您可以使用以下注释来内联忽略规则。
从 tflint
v0.40.0
Ref 添加了另外两种注释样式。不同的规则可以应用于资源块或其中的元素。
以下面示例中的
terraform_naming_convention
为例。此规则描述了资源的 terraform 命名约定违规。要忽略此语句,该指令位于块上方。As of tflint
v0.39.3
RefYou can use an the following annotation to inline-ignore rules.
As of tflint
v0.40.0
Ref adds two more annotation styles.Different rules can apply to resource blocks or to the elements within.
Take
terraform_naming_convention
in the example below. This rule describes the terraform naming convention violation for the resource. To ignore this statement the directive is located above the block.您需要在需要忽略的块之外添加注释。例如:
您还可以放置多个忽略:
最后您可以从 lint 中排除该块:
注意:取决于被忽略的块,您也可以尝试将 tflint-ignore 放在块内 if该资源尚未创建。
参考:
You need to add an annotation outside the block that need to be ignored. For example :
you can also put multiple ignores:
and finally you can exclude the block from the lint:
Note: Depends from the ignored block, you may also try to put the
tflint-ignore
inside the block if the ressource is not created already.reference:
我用一个创建 dynamodb 表的 terraform 文件遇到了这个问题,上面的建议都不起作用。我已经在资源块内部和外部尝试过这些方法,但它们不起作用:
tflint 项目当前版本为 v0.47,此时可能不应该使用它。
I've run into this with a terraform file that creates a dynamodb table, and none of the suggestions above work. I've tried these both inside and outside of the resource block and they don't work:
The tflint project is currently at v0.47 and it probably shouldn't be used at this point.
顺便说一句,我已经成功地通过使用空设备
/dev/null
来抑制警告消息,并将脚本生成的 STDERR 日志重定向到2> 。 /dev/null
。最终代码:
By the way, I have managed to suppress the warning messages by making use of null device
/dev/null
and redirected STDERR logs generated by script to2> /dev/null
.Final Code: