Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decoder: Update comments about validation of other Origin types #1396

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions internal/decoder/validations/unreferenced_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ func UnreferencedOrigins(ctx context.Context, pathCtx *decoder.PathContext) lang
diagsMap := make(lang.DiagnosticsMap)

for _, origin := range pathCtx.ReferenceOrigins {
matchableOrigin, ok := origin.(reference.MatchableOrigin)
localOrigin, ok := origin.(reference.LocalOrigin)
if !ok {
// we don't report on other origins to avoid complexity for now
// other origins would need to be matched against other
// modules/directories and we cannot be sure the targets are
// available within the workspace or were parsed/decoded/collected
// at the time this event occurs
// We avoid reporting on other origin types.
//
// DirectOrigin is represented as module's source
// and we already validate existence of the local module
// and avoiding linking to a non-existent module in terraform-schema
// https://github.com/hashicorp/terraform-schema/blob/b39f3de0/schema/module_schema.go#L212-L232
//
// PathOrigin is represented as module inputs
// and we can validate module inputs more meaningfully
// as attributes in body (module block), e.g. raise that
// an input is required or unknown, rather than "reference"
// lacking a corresponding target.
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
}

address := matchableOrigin.Address()
address := localOrigin.Address()

if len(address) > 2 {
// We temporarily ignore references with more than 2 segments
Expand All @@ -54,7 +54,7 @@ func UnreferencedOrigins(ctx context.Context, pathCtx *decoder.PathContext) lang
continue
}

_, ok = pathCtx.ReferenceTargets.Match(matchableOrigin)
_, ok = pathCtx.ReferenceTargets.Match(localOrigin)
if !ok {
// target not found
fileName := origin.OriginRange().Filename
Expand Down