diff --git a/cmd/tofu/commands.go b/cmd/tofu/commands.go index 0a6cc5b81e..f314c2f1f6 100644 --- a/cmd/tofu/commands.go +++ b/cmd/tofu/commands.go @@ -88,10 +88,11 @@ func initCommands( WorkingDir: wd, View: view.SetRunningInAutomation(inAutomation), SystemArgs: arguments.System{ - RunningInAutomation: inAutomation, - CLIConfigDir: configDir, - PluginCacheDir: config.PluginCacheDir, - GlobalPluginDirs: globalPluginDirs(), + RunningInAutomation: inAutomation, + CLIConfigDir: configDir, + PluginCacheDir: config.PluginCacheDir, + GlobalPluginDirs: globalPluginDirs(), + AllowExperimentalFeatures: experimentsAreAllowed(), }, Services: services, @@ -113,8 +114,6 @@ func initCommands( ProviderDevOverrides: providerDevOverrides, UnmanagedProviders: unmanagedProviders, - AllowExperimentalFeatures: experimentsAreAllowed(), - // ProviderSourceLocationConfig is used for some commands that do not make // use of the OpenTofu configuration files. Therefore, there is no way to configure // the retries from other places than env vars. diff --git a/internal/command/arguments/system.go b/internal/command/arguments/system.go index a8e568cd0e..14dcd49218 100644 --- a/internal/command/arguments/system.go +++ b/internal/command/arguments/system.go @@ -28,4 +28,18 @@ type System struct { // GlobalPluginDirs contains additional paths to search for plugins GlobalPluginDirs []string + + // AllowExperimentalFeatures controls whether the current build of OpenTofu + // has experimental features enabled. + // + // In normal code this would be set by package main only in builds + // explicitly marked as being alpha releases or development snapshots, + // making experimental features unavailable otherwise. Test code may + // choose to set this if it needs to exercise experimental features. + // + // Some experiments predated the addition of this setting, and may + // therefore still be available even if this flag is false. Our intent + // is that all/most _future_ experiments will be unavailable unless this + // flag is set, to reinforce that experiments are not for production use. + AllowExperimentalFeatures bool } diff --git a/internal/command/meta.go b/internal/command/meta.go index 93aacbc339..513e8d72ed 100644 --- a/internal/command/meta.go +++ b/internal/command/meta.go @@ -144,24 +144,6 @@ type Meta struct { // just trusting that someone else did it before running OpenTofu. UnmanagedProviders map[addrs.Provider]*plugin.ReattachConfig - // AllowExperimentalFeatures controls whether a command that embeds this - // Meta is permitted to make use of experimental OpenTofu features. - // - // Set this field only during the initial creation of Meta. If you change - // this field after calling methods of type Meta then the resulting - // behavior is undefined. - // - // In normal code this would be set by package main only in builds - // explicitly marked as being alpha releases or development snapshots, - // making experimental features unavailable otherwise. Test code may - // choose to set this if it needs to exercise experimental features. - // - // Some experiments predated the addition of this setting, and may - // therefore still be available even if this flag is false. Our intent - // is that all/most _future_ experiments will be unavailable unless this - // flag is set, to reinforce that experiments are not for production use. - AllowExperimentalFeatures bool - // ---------------------------------------------------------- // Protected: commands can set these // ---------------------------------------------------------- diff --git a/internal/command/meta_backend.go b/internal/command/meta_backend.go index a2314612dc..a6995f5d4d 100644 --- a/internal/command/meta_backend.go +++ b/internal/command/meta_backend.go @@ -109,7 +109,7 @@ func (m *Meta) Backend(ctx context.Context, opts *BackendOpts, enc encryption.St opts = &BackendOpts{} } - if m.AllowExperimentalFeatures { + if m.SystemArgs.AllowExperimentalFeatures { // TEMP: While we're in early development of the new language runtime // we have an experimental shim to enable it using an environment // variable, but that's allowed only in builds where experimental @@ -327,7 +327,7 @@ func (m *Meta) selectWorkspace(ctx context.Context, b backend.Backend) error { func (m *Meta) BackendForLocalPlan(ctx context.Context, settings plans.Backend, enc encryption.StateEncryption) (backend.Enhanced, tfdiags.Diagnostics) { var diags tfdiags.Diagnostics - if m.AllowExperimentalFeatures { + if m.SystemArgs.AllowExperimentalFeatures { // TEMP: While we're in early development of the new language runtime // we have an experimental shim to enable it using an environment // variable, but that's allowed only in builds where experimental diff --git a/internal/command/meta_config.go b/internal/command/meta_config.go index 2cd1f42cee..19c0fe9025 100644 --- a/internal/command/meta_config.go +++ b/internal/command/meta_config.go @@ -444,7 +444,7 @@ func (m *Meta) initConfigLoader() (*configload.Loader, error) { if err != nil { return nil, err } - loader.AllowLanguageExperiments(m.AllowExperimentalFeatures) + loader.AllowLanguageExperiments(m.SystemArgs.AllowExperimentalFeatures) m.configLoader = loader if m.View != nil { m.View.SetConfigSources(loader.Sources)