s3.tfvars
bucket = "first-bucket"
acl="private"
env = "dev"
owner = "[email protected] /cdn-cgi/l/email-protection"
var1 = "unused variable"
s3.tf
resource "aws_s3_bucket" "abucket" {
bucket = var.bucket
acl = "private"
tags = {
Environment = var.env
Owner = var.owner
}
}
var1 没有在我的代码中使用,尽管它是在 tfvars 中声明的,如上所示。
当我运行以下命令时
terraform plan -var-file=s3.tfvars
...,我收到以下警告消息:
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.
有没有办法将此警告捕获为错误?或者有没有其他方法可以找出所有未使用变量的列表?
你想使用tflint https://github.com/terraform-linters/tflint.
mkdir test/
cd test/
echo 'variable "what" {}' > main.tf
Add .tflint.hcl
rule "terraform_unused_declarations" {
enabled = true
}
$ tflint --init
$ tflint
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)