Skip to content

Commit

Permalink
feat: make Terraform functions available in stacks files (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarm authored Aug 5, 2024
1 parent b8beda3 commit 9db52d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/ENHANCEMENTS-20240731-155657.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: ENHANCEMENTS
body: Support Terraform functions in stack files
time: 2024-07-31T15:56:57.234803+02:00
custom:
Issue: "1781"
Repository: terraform-ls
11 changes: 11 additions & 0 deletions internal/features/stacks/decoder/path_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/hcl-lang/decoder"
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl-lang/reference"
"github.com/hashicorp/hcl-lang/schema"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform-ls/internal/features/stacks/ast"
"github.com/hashicorp/terraform-ls/internal/features/stacks/state"
Expand Down Expand Up @@ -100,6 +101,7 @@ func stackPathContext(record *state.StackRecord, stateReader CombinedReader) (*d
ReferenceOrigins: make(reference.Origins, 0),
ReferenceTargets: make(reference.Targets, 0),
Files: make(map[string]*hcl.File, 0),
Functions: mustFunctionsForVersion(version),
}

// TODO: Add reference origins and targets if needed
Expand Down Expand Up @@ -195,3 +197,12 @@ func (pr *PathReader) Paths(ctx context.Context) []lang.Path {

return paths
}

func mustFunctionsForVersion(v *version.Version) map[string]schema.FunctionSignature {
s, err := tfschema.FunctionsForVersion(v)
if err != nil {
// this should never happen
panic(err)
}
return s
}

0 comments on commit 9db52d4

Please sign in to comment.