Skip to content

Commit d528ba8

Browse files
committed
fix: Allow detection of experiments in config early in init, but re-parse the root module after it might have been impacted by use of the -from-module flag (parsing may yield something different the second time!). Diagnostics still need to be passed though.
1 parent 5df195f commit d528ba8

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

internal/command/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func (c *InitCommand) Run(args []string) int {
7474
// > The terraform block in the configuration lists the `pluggable_state_stores` experiment.
7575
if c.Meta.AllowExperimentalFeatures && rootMod.ActiveExperiments.Has(experiments.PluggableStateStores) {
7676
// TODO(SarahFrench/radeksimko): Remove forked init logic once feature is no longer experimental
77-
return c.runPssInit(initArgs, view, rootMod, rootModDiags)
77+
return c.runPssInit(initArgs, view, rootModDiags)
7878
} else {
79-
return c.run(initArgs, view, rootMod, rootModDiags)
79+
return c.run(initArgs, view, rootModDiags)
8080
}
8181
}
8282

internal/command/init_run.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"go.opentelemetry.io/otel/trace"
2424
)
2525

26-
func (c *InitCommand) run(initArgs *arguments.Init, view views.Init, rootModEarly *configs.Module, earlyConfDiags tfdiags.Diagnostics) int {
26+
func (c *InitCommand) run(initArgs *arguments.Init, view views.Init, earlyConfDiags tfdiags.Diagnostics) int {
2727
var diags tfdiags.Diagnostics
2828

2929
c.forceInitCopy = initArgs.ForceInitCopy
@@ -130,14 +130,13 @@ func (c *InitCommand) run(initArgs *arguments.Init, view views.Init, rootModEarl
130130
return 0
131131
}
132132

133-
// If the passed root module is nil, attempt to parse it.
134-
// At this point we load just the root module to begin backend and module initialization
133+
// We parse the root module here because it may have been affected by use of init's -from-module flag.
134+
// However we need to use diagnostics passed in from calling code due to detection of experiments in the config.
135+
// See calling code for more context.
135136
//
136-
// TODO(SarahFrench/radeksimko): Once PSS's experiment is over, remove use of arguments and
137-
// restore parsing of config to always happen here in this code instead of calling code.
138-
if rootModEarly == nil {
139-
rootModEarly, earlyConfDiags = c.loadSingleModuleWithTests(path, initArgs.TestsDirectory)
140-
}
137+
// TODO(SarahFrench/radeksimko): Once PSS's experiment is over, remove use of earlyConfDiags argument and
138+
// restore parsing of config to only happen here in this code instead of calling code.
139+
rootModEarly, _ := c.loadSingleModuleWithTests(path, initArgs.TestsDirectory)
141140

142141
// There may be parsing errors in config loading but these will be shown later _after_
143142
// checking for core version requirement errors. Not meeting the version requirement should

internal/command/init_run_experiment.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
// `runPssInit` is an altered version of the logic in `run` that contains changes
3232
// related to the PSS project. This is used by the (InitCommand.Run method only if Terraform has
3333
// experimental features enabled.
34-
func (c *InitCommand) runPssInit(initArgs *arguments.Init, view views.Init, rootModEarly *configs.Module, earlyConfDiags tfdiags.Diagnostics) int {
34+
func (c *InitCommand) runPssInit(initArgs *arguments.Init, view views.Init, earlyConfDiags tfdiags.Diagnostics) int {
3535
var diags tfdiags.Diagnostics
3636

3737
c.forceInitCopy = initArgs.ForceInitCopy
@@ -138,14 +138,13 @@ func (c *InitCommand) runPssInit(initArgs *arguments.Init, view views.Init, root
138138
return 0
139139
}
140140

141-
// If the passed root module is nil, attempt to parse it.
142-
// At this point we load just the root module to begin backend and module initialization
141+
// We parse the root module here because it may have been affected by use of init's -from-module flag.
142+
// However we need to use diagnostics passed in from calling code due to detection of experiments in the config.
143+
// See calling code for more context.
143144
//
144-
// TODO(SarahFrench/radeksimko): Once PSS's experiment is over, remove use of arguments and
145-
// restore parsing of config to always happen here in this code instead of calling code.
146-
if rootModEarly == nil {
147-
rootModEarly, earlyConfDiags = c.loadSingleModuleWithTests(path, initArgs.TestsDirectory)
148-
}
145+
// TODO(SarahFrench/radeksimko): Once PSS's experiment is over, remove use of earlyConfDiags argument and
146+
// restore parsing of config to only happen here in this code instead of calling code.
147+
rootModEarly, _ := c.loadSingleModuleWithTests(path, initArgs.TestsDirectory)
149148

150149
// There may be parsing errors in config loading but these will be shown later _after_
151150
// checking for core version requirement errors. Not meeting the version requirement should

0 commit comments

Comments
 (0)