mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-21 23:00:42 -08:00
feat(misconf): variable support for Terraform Plan (#7228)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
This commit is contained in:
@@ -1746,6 +1746,33 @@ func TestTFVarsFileDoesNotExist(t *testing.T) {
|
||||
assert.ErrorContains(t, err, "file does not exist")
|
||||
}
|
||||
|
||||
func Test_OptionsWithTfVars(t *testing.T) {
|
||||
fs := testutil.CreateFS(t, map[string]string{
|
||||
"main.tf": `resource "test" "this" {
|
||||
foo = var.foo
|
||||
}
|
||||
variable "foo" {}
|
||||
`})
|
||||
|
||||
parser := New(fs, "", OptionsWithTfVars(
|
||||
map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
},
|
||||
))
|
||||
|
||||
require.NoError(t, parser.ParseFS(context.TODO(), "."))
|
||||
|
||||
modules, _, err := parser.EvaluateAll(context.TODO())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, modules, 1)
|
||||
|
||||
rootModule := modules[0]
|
||||
|
||||
blocks := rootModule.GetResourcesByType("test")
|
||||
assert.Len(t, blocks, 1)
|
||||
assert.Equal(t, "bar", blocks[0].GetAttribute("foo").Value().AsString())
|
||||
}
|
||||
|
||||
func TestDynamicWithIterator(t *testing.T) {
|
||||
fsys := fstest.MapFS{
|
||||
"main.tf": &fstest.MapFile{
|
||||
|
||||
Reference in New Issue
Block a user