本文介绍了如何查找未在 Terraform 代码中使用的所有 tfvars 变量的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
bucket = "first-bucket"
acl="private"
env = "dev"
owner = "[email protected]"
var1 = "unused variable"
s3.tf
resource "aws_s3_bucket" "abucket" {
bucket = var.bucket
acl = "private"
tags = {
Environment = var.env
Owner = var.owner
}
}
var1 未在我的代码中使用,即使它在 tfvars 中声明,如上所示.
var1 is not used in my code even though it is declared in tfvars as shown above.
当我运行以下命令时
terraform plan -var-file=s3.tfvars
...,我收到以下警告消息:
..., I get the following warning message:
Warning: Value for undeclared variable
The root module does not declare a variable named "var1" but a value was
found in file "s3.tfvars". To use this value, add a "variable" block to the
configuration.
有没有办法将此警告捕获为错误?或者有没有其他方法可以找出所有未使用变量的列表?
Is there a way to capture this warning as an error? Or is there Any other way to find out list of all unused variables?
推荐答案
你想使用 tflint一个>.
mkdir test/
cd test/
echo 'variable "what" {}' > main.tf
$ tflint --enable-rule=terraform_unused_declarations
1 issue(s) found:
Warning: variable "what" is declared but not used (terraform_unused_declarations)
on main.tf line 1:
1: variable "what" {}
Reference: https://github.com/terraform-linters/tflint/blob/v0.28.1/docs/rules/terraform_unused_declarations.md
这篇关于如何查找未在 Terraform 代码中使用的所有 tfvars 变量的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!