From 188eeac4ff8584e7b448ea2d5b1ea83afa41f3ac Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 2 Mar 2026 16:47:57 +0100 Subject: [PATCH] remove now obsolete ReadConfig on planfile --- internal/plans/planfile/reader.go | 29 ----------------------------- internal/terraform/context_test.go | 20 +++++++++++++++++++- internal/terraform/planfile_test.go | 10 ---------- 3 files changed, 19 insertions(+), 40 deletions(-) diff --git a/internal/plans/planfile/reader.go b/internal/plans/planfile/reader.go index 2a54187d1b..da6c5ca87e 100644 --- a/internal/plans/planfile/reader.go +++ b/internal/plans/planfile/reader.go @@ -10,7 +10,6 @@ import ( "io" "os" - "github.com/hashicorp/terraform/internal/configs" "github.com/hashicorp/terraform/internal/configs/configload" "github.com/hashicorp/terraform/internal/depsfile" "github.com/hashicorp/terraform/internal/plans" @@ -191,34 +190,6 @@ func (r *Reader) ReadConfigSnapshot() (*configload.Snapshot, error) { return ReadConfigSnapshot(&r.zip.Reader) } -// ReadConfig reads the configuration embedded in the plan file. -// -// Internally this function delegates to the configs/configload package to -// parse the embedded configuration and so it returns diagnostics (rather than -// a native Go error as with other methods on Reader). -// TODO remove? -func (r *Reader) ReadConfig(allowLanguageExperiments bool) (*configs.Config, tfdiags.Diagnostics) { - var diags tfdiags.Diagnostics - - snap, err := r.ReadConfigSnapshot() - if err != nil { - diags = diags.Append(tfdiags.Sourceless( - tfdiags.Error, - "Failed to read configuration from plan file", - fmt.Sprintf("The configuration file snapshot in the plan file could not be read: %s.", err), - )) - return nil, diags - } - - loader := configload.NewLoaderFromSnapshot(snap) - loader.AllowLanguageExperiments(allowLanguageExperiments) - rootDir := snap.Modules[""].Dir // Root module base directory - config, configDiags := loader.LoadStaticConfig(rootDir) - diags = diags.Append(configDiags) - - return config, diags -} - // ReadDependencyLocks reads the dependency lock information embedded in // the plan file. // diff --git a/internal/terraform/context_test.go b/internal/terraform/context_test.go index 61feeccd8f..ef4276874c 100644 --- a/internal/terraform/context_test.go +++ b/internal/terraform/context_test.go @@ -810,7 +810,25 @@ func contextOptsForPlanViaFile(t *testing.T, configSnap *configload.Snapshot, pl return nil, nil, nil, err } - config, diags := pr.ReadConfig(false) + snap, err := pr.ReadConfigSnapshot() + if err != nil { + return nil, nil, nil, err + } + + loader := configload.NewLoaderFromSnapshot(snap) + rootMod, hclDiags := loader.LoadRootModule(snap.Modules[""].Dir) + diags := tfdiags.Diagnostics(nil).Append(hclDiags) + if diags.HasErrors() { + return nil, nil, nil, diags.Err() + } + + config, buildDiags := BuildConfigWithGraph( + rootMod, + loader.ModuleWalker(), + nil, + configs.MockDataLoaderFunc(loader.LoadExternalMockData), + ) + diags = diags.Append(buildDiags) if diags.HasErrors() { return nil, nil, nil, diags.Err() } diff --git a/internal/terraform/planfile_test.go b/internal/terraform/planfile_test.go index b3fe65fe5c..ca0f59c6e3 100644 --- a/internal/terraform/planfile_test.go +++ b/internal/terraform/planfile_test.go @@ -156,16 +156,6 @@ func TestRoundtrip(t *testing.T) { } }) - t.Run("ReadConfig", func(t *testing.T) { - // Reading from snapshots is tested in the configload package, so - // here we'll just test that we can successfully do it, to see if the - // glue code in _this_ package is correct. - _, diags := pr.ReadConfig(false) - if diags.HasErrors() { - t.Errorf("when reading config: %s", diags.Err()) - } - }) - t.Run("ReadDependencyLocks", func(t *testing.T) { locksOut, diags := pr.ReadDependencyLocks() if diags.HasErrors() {