-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(TFECO-7366) Stacks: parse
terraform-sources.json
to support remote…
… component sources (#1836) * support parsing terraform-sources.json files created by tfstacks cli to support completions for remote modules in stacks projects * log errors * add tests * add changie entry * fix: ensure test also succeeds on windows using backslashes in paths * simplify terraform sources parsing code * parse registry modules from terraform-sources.json as well * Bump terraform-schema to `1392f74`
- Loading branch information
Showing
17 changed files
with
610 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: ENHANCEMENTS | ||
body: 'Stacks: parse terraform-sources.json to support remote component sources' | ||
time: 2024-10-28T09:04:53.004252+01:00 | ||
custom: | ||
Issue: "1836" | ||
Repository: terraform-ls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package jobs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-ls/internal/document" | ||
"github.com/hashicorp/terraform-ls/internal/features/rootmodules/state" | ||
"github.com/hashicorp/terraform-ls/internal/job" | ||
"github.com/hashicorp/terraform-ls/internal/terraform/datadir" | ||
op "github.com/hashicorp/terraform-ls/internal/terraform/module/operation" | ||
) | ||
|
||
// ParseTerraformSources parses the NEW* "module manifest" which | ||
// contains records of installed modules, e.g. where they're | ||
// installed on the filesystem. | ||
// This is useful for processing any modules which are not local | ||
// nor hosted in the Registry (which would be handled by | ||
// [GetModuleDataFromRegistry]). | ||
// NEW* as there is a new terraform-sources.json file format which currently only exists for stacks. | ||
func ParseTerraformSources(ctx context.Context, fs ReadOnlyFS, rootStore *state.RootStore, modPath string) error { | ||
mod, err := rootStore.RootRecordByPath(modPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Avoid parsing if it is already in progress or already known | ||
if mod.TerraformSourcesState != op.OpStateUnknown && !job.IgnoreState(ctx) { | ||
return job.StateNotChangedErr{Dir: document.DirHandleFromPath(modPath)} | ||
} | ||
|
||
err = rootStore.SetTerraformSourcesState(modPath, op.OpStateLoading) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tfs, err := datadir.ParseTerraformSourcesFromFile(modPath) | ||
if err != nil { | ||
err := fmt.Errorf("failed to parse terraform sources: %w", err) | ||
sErr := rootStore.UpdateTerraformSources(modPath, nil, err) | ||
if sErr != nil { | ||
return sErr | ||
} | ||
return err | ||
} | ||
|
||
sErr := rootStore.UpdateTerraformSources(modPath, tfs, err) | ||
|
||
if sErr != nil { | ||
return sErr | ||
} | ||
return err | ||
} |
Oops, something went wrong.