remove now obsolete ReadConfig on planfile

pull/38226/head
Daniel Schmidt 1 month ago
parent 8fd8a48a06
commit 188eeac4ff

@ -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.
//

@ -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()
}

@ -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() {

Loading…
Cancel
Save