mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-15 09:00:59 -08:00
fix(misconf): allow null values only for tf variables (#8112)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
This commit is contained in:
@@ -2161,3 +2161,29 @@ resource "foo" "this" {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttrRefToNullVariable(t *testing.T) {
|
||||
fsys := fstest.MapFS{
|
||||
"main.tf": &fstest.MapFile{Data: []byte(`variable "name" {
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket" "example" {
|
||||
bucket = var.name
|
||||
}`)},
|
||||
}
|
||||
|
||||
parser := New(fsys, "", OptionStopOnHCLError(true))
|
||||
|
||||
require.NoError(t, parser.ParseFS(context.TODO(), "."))
|
||||
|
||||
_, err := parser.Load(context.TODO())
|
||||
require.NoError(t, err)
|
||||
|
||||
modules, _, err := parser.EvaluateAll(context.TODO())
|
||||
require.NoError(t, err)
|
||||
|
||||
val := modules.GetResourcesByType("aws_s3_bucket")[0].GetAttribute("bucket").GetRawValue()
|
||||
assert.Nil(t, val)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user