Skip to content

Commit

Permalink
(TFECO-7942) builtin refs from tf schema (#1854)
Browse files Browse the repository at this point in the history
* source version specific built-in references from terraform-schema

* add changie entry
  • Loading branch information
ansgarm authored Nov 7, 2024
1 parent 1d863ba commit 8e8ee58
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 59 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/ENHANCEMENTS-20241029-161707.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: ENHANCEMENTS
body: Support terraform.applying built-in reference starting at TF 1.10
time: 2024-10-29T16:17:07.267245+01:00
custom:
Issue: "1854"
Repository: terraform-ls
3 changes: 3 additions & 0 deletions internal/features/modules/decoder/module_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func modulePathContext(mod *state.ModuleRecord, stateReader CombinedReader) (*de
}
}

// append Terraform version specific path targets that are available in all modules (builtin references)
pathCtx.ReferenceTargets = append(pathCtx.ReferenceTargets, referencesForModule(mod, stateReader)...)

for name, f := range mod.ParsedModuleFiles {
pathCtx.Files[name.String()] = f
}
Expand Down
17 changes: 17 additions & 0 deletions internal/features/modules/decoder/references.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package decoder

import (
"github.com/hashicorp/hcl-lang/reference"
"github.com/hashicorp/terraform-ls/internal/features/modules/state"
tfschema "github.com/hashicorp/terraform-schema/schema"
)

func referencesForModule(mod *state.ModuleRecord, stateReader CombinedReader) reference.Targets {
modPath := mod.Path()
resolvedVersion := tfschema.ResolveVersion(stateReader.TerraformVersion(modPath), mod.Meta.CoreRequirements)

return tfschema.BuiltinReferencesForVersion(resolvedVersion, modPath)
}
57 changes: 0 additions & 57 deletions internal/features/modules/jobs/builtin_references.go

This file was deleted.

2 changes: 0 additions & 2 deletions internal/features/modules/jobs/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func DecodeReferenceTargets(ctx context.Context, modStore *state.ModuleStore, ro
}
targets, rErr := pd.CollectReferenceTargets()

targets = append(targets, builtinReferences(modPath)...)

sErr := modStore.UpdateReferenceTargets(modPath, targets, rErr)
if sErr != nil {
return sErr
Expand Down

0 comments on commit 8e8ee58

Please sign in to comment.