Skip to content

Commit 43bde21

Browse files
committed
Narrow Unsupported attribute dismissal to missing-attribute Detail and add Unknown variable test coverage.
1 parent 29644d7 commit 43bde21

2 files changed

Lines changed: 7 additions & 19 deletions

File tree

pkg/parser/terraform/data_source.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,10 @@ func parseDataSourceBody(ctx context.Context, body *hclsyntax.Body, inputVariabl
245245
Functions: functions.TerraformFuncs,
246246
})
247247

248-
// Dismiss diagnostics caused by unresolvable variable references so that
249-
// statically-known fields in the same block are still analysed.
250-
// "Unknown variable" – var/local/module absent from the eval context entirely.
251-
// "Unsupported attribute" (narrowed to the "does not have an attribute named"
252-
// detail) – var IS in the context as a cty.Object of known defaults, but
253-
// the specific variable has no default and is therefore not an attribute on
254-
// that object. We narrow by Detail to avoid silently swallowing unrelated
255-
// attribute errors (e.g. accessing a non-existent field on a resource).
256-
// Both cases leave the affected field as cty.DynamicVal, handled below by
257-
// cty.UnknownAsNull.
248+
// Dismiss unresolvable variable references; both leave the field as
249+
// cty.DynamicVal which cty.UnknownAsNull handles below.
250+
// "Unsupported attribute" is narrowed by Detail to avoid swallowing
251+
// unrelated attribute errors on non-variable objects.
258252
for _, decErr := range decodeErrs {
259253
isUnknownVar := decErr.Summary == "Unknown variable"
260254
isUnsupportedAttrOnVar := decErr.Summary == "Unsupported attribute" &&

pkg/parser/terraform/data_source_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ func Test_getDataSourcePolicy(t *testing.T) {
2020
type args struct {
2121
currentPath string
2222
resourceName string
23-
// inputVars seeds the variable map passed to getDataSourcePolicy.
24-
// nil means an empty map (no var/local context), which is fine for
25-
// fixtures that contain no variable references.
26-
inputVars converter.VariableMap
23+
inputVars converter.VariableMap // nil means empty map
2724
}
2825
tests := []struct {
2926
name string
@@ -49,9 +46,7 @@ func Test_getDataSourcePolicy(t *testing.T) {
4946
`,
5047
},
5148
{
52-
// Production path: getInputVariables sets "var" as a cty.Object of
53-
// resolved defaults. A no-default variable is absent from the object,
54-
// so var.sid_value raises "Unsupported attribute".
49+
// "var" present but no default: raises "Unsupported attribute".
5550
name: "should not drop policy when scalar fields reference variables with no default (production var context)",
5651
args: args{
5752
currentPath: filepath.Join("..", "..", "..", "test", "fixtures", "test_terraform_data_source_unknown_vars"),
@@ -62,8 +57,7 @@ func Test_getDataSourcePolicy(t *testing.T) {
6257
`,
6358
},
6459
{
65-
// Absent var context: "var" not in inputVars at all, so var.sid_value
66-
// raises "Unknown variable".
60+
// "var" absent entirely: raises "Unknown variable".
6761
name: "should not drop policy when scalar fields reference variables with no var context",
6862
args: args{
6963
currentPath: filepath.Join("..", "..", "..", "test", "fixtures", "test_terraform_data_source_unknown_vars"),

0 commit comments

Comments
 (0)