Skip to content

Commit

Permalink
validations: Limit ref. validation to only LocalOrigin(s) (#1379)
Browse files Browse the repository at this point in the history
* validations: Limit ref. validation to only LocalOrigin(s)

* validations: add test for disabled origins
  • Loading branch information
radeksimko authored and dbanck committed Sep 28, 2023
1 parent a8816a0 commit c4b7399
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/decoder/validations/unreferenced_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func UnreferencedOrigins(ctx context.Context, pathCtx *decoder.PathContext) lang
continue
}

_, ok = origin.(reference.LocalOrigin)
if !ok {
// we avoid reporting on origins outside of the current module
// for now, to reduce complexity and reduce performance impact
continue
}

// we only initially validate variables
// resources and data sources can have unknown schema
// and will be researched at a later point
Expand Down
22 changes: 22 additions & 0 deletions internal/decoder/validations/unreferenced_origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ func TestUnreferencedOrigins(t *testing.T) {
},
},
},
{
name: "unsupported path origins (module input)",
origins: reference.Origins{
reference.PathOrigin{
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{},
End: hcl.Pos{},
},
TargetAddr: lang.Address{
lang.RootStep{Name: "var"},
lang.AttrStep{Name: "foo"},
},
TargetPath: lang.Path{
Path: "./submodule",
LanguageID: "terraform",
},
Constraints: reference.OriginConstraints{},
},
},
want: lang.DiagnosticsMap{},
},
{
name: "many undeclared variables",
origins: reference.Origins{
Expand Down

0 comments on commit c4b7399

Please sign in to comment.