fix(misconf): allow null values only for tf variables (#8112)

Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
This commit is contained in:
Nikita Pivkin
2025-01-10 07:52:51 +06:00
committed by GitHub
parent a0429f773b
commit 23dc3a6753
3 changed files with 40 additions and 2 deletions

View File

@@ -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)
}