Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions internal/command/arguments/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ type Init struct {

Args []string

// The -enable-pluggable-state-storage-experiment flag is used in control flow logic in the init command.
// TODO(SarahFrench/radeksimko): Remove this once the feature is no longer
// experimental
EnablePssExperiment bool

// CreateDefaultWorkspace indicates whether the default workspace should be created by
// Terraform when initializing a state store for the first time.
CreateDefaultWorkspace bool
Expand Down Expand Up @@ -118,9 +113,6 @@ func ParseInit(args []string, experimentsEnabled bool) (*Init, tfdiags.Diagnosti
cmdFlags.Var(&init.PluginPath, "plugin-dir", "plugin directory")
cmdFlags.BoolVar(&init.CreateDefaultWorkspace, "create-default-workspace", true, "when -input=false, use this flag to block creation of the default workspace")

// Used for enabling experimental code that's invoked before configuration is parsed.
cmdFlags.BoolVar(&init.EnablePssExperiment, "enable-pluggable-state-storage-experiment", false, "Enable the pluggable state storage experiment")

if err := cmdFlags.Parse(args); err != nil {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
Expand All @@ -129,10 +121,6 @@ func ParseInit(args []string, experimentsEnabled bool) (*Init, tfdiags.Diagnosti
))
}

if v := os.Getenv("TF_ENABLE_PLUGGABLE_STATE_STORAGE"); v != "" {
init.EnablePssExperiment = true
}

if v := os.Getenv("TF_SKIP_CREATE_DEFAULT_WORKSPACE"); v != "" {
// If TF_SKIP_CREATE_DEFAULT_WORKSPACE is set it will override
// a -create-default-workspace=true flag that's set explicitly,
Expand All @@ -142,13 +130,6 @@ func ParseInit(args []string, experimentsEnabled bool) (*Init, tfdiags.Diagnosti

if !experimentsEnabled {
// If experiments aren't enabled then these flags should not be used.
if init.EnablePssExperiment {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Cannot use -enable-pluggable-state-storage-experiment flag without experiments enabled",
"Terraform cannot use the -enable-pluggable-state-storage-experiment flag (or TF_ENABLE_PLUGGABLE_STATE_STORAGE environment variable) unless experiments are enabled.",
))
}
if !init.CreateDefaultWorkspace {
// Can only be set to false by using the flag
// and we cannot identify if -create-default-workspace=true is set explicitly.
Expand All @@ -158,15 +139,6 @@ func ParseInit(args []string, experimentsEnabled bool) (*Init, tfdiags.Diagnosti
"Terraform cannot use the -create-default-workspace flag (or TF_SKIP_CREATE_DEFAULT_WORKSPACE environment variable) unless experiments are enabled.",
))
}
} else {
// Errors using flags despite experiments being enabled.
if !init.CreateDefaultWorkspace && !init.EnablePssExperiment {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Cannot use -create-default-workspace=false flag unless the pluggable state storage experiment is enabled",
"Terraform cannot use the -create-default-workspace=false flag (or TF_SKIP_CREATE_DEFAULT_WORKSPACE environment variable) unless you also supply the -enable-pluggable-state-storage-experiment flag (or set the TF_ENABLE_PLUGGABLE_STATE_STORAGE environment variable).",
))
}
}

if init.MigrateState && init.Json {
Expand Down
30 changes: 4 additions & 26 deletions internal/command/arguments/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ func TestParseInit_basicValid(t *testing.T) {
},
},
"setting multiple options": {
[]string{"-backend=false", "-force-copy=true",
[]string{
"-backend=false", "-force-copy=true",
"-from-module=./main-dir", "-json", "-get=false",
"-lock=false", "-lock-timeout=10s", "-reconfigure=true",
"-upgrade=true", "-lockfile=readonly", "-compact-warnings=true",
"-ignore-remote-version=true", "-test-directory=./test-dir"},
"-ignore-remote-version=true", "-test-directory=./test-dir",
},
&Init{
FromModule: "./main-dir",
Lockfile: "readonly",
Expand Down Expand Up @@ -182,18 +184,6 @@ func TestParseInit_experimentalFlags(t *testing.T) {
wantErr string
experimentsEnabled bool
}{
"error: -enable-pluggable-state-storage-experiment and experiments are disabled": {
args: []string{"-enable-pluggable-state-storage-experiment"},
experimentsEnabled: false,
wantErr: "Cannot use -enable-pluggable-state-storage-experiment flag without experiments enabled",
},
"error: TF_ENABLE_PLUGGABLE_STATE_STORAGE is set and experiments are disabled": {
envs: map[string]string{
"TF_ENABLE_PLUGGABLE_STATE_STORAGE": "1",
},
experimentsEnabled: false,
wantErr: "Cannot use -enable-pluggable-state-storage-experiment flag without experiments enabled",
},
"error: -create-default-workspace=false and experiments are disabled": {
args: []string{"-create-default-workspace=false"},
experimentsEnabled: false,
Expand All @@ -206,18 +196,6 @@ func TestParseInit_experimentalFlags(t *testing.T) {
experimentsEnabled: false,
wantErr: "Cannot use -create-default-workspace flag without experiments enabled",
},
"error: -create-default-workspace=false used without -enable-pluggable-state-storage-experiment, while experiments are enabled": {
args: []string{"-create-default-workspace=false"},
experimentsEnabled: true,
wantErr: "Cannot use -create-default-workspace=false flag unless the pluggable state storage experiment is enabled",
},
"error: TF_SKIP_CREATE_DEFAULT_WORKSPACE used without -enable-pluggable-state-storage-experiment, while experiments are enabled": {
envs: map[string]string{
"TF_SKIP_CREATE_DEFAULT_WORKSPACE": "1",
},
experimentsEnabled: true,
wantErr: "Cannot use -create-default-workspace=false flag unless the pluggable state storage experiment is enabled",
},
}

for name, tc := range testCases {
Expand Down
5 changes: 2 additions & 3 deletions internal/command/e2etest/pluggable_state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func TestPrimary_stateStore_unmanaged_separatePlan(t *testing.T) {
t.Chdir(tf.WorkDir())

//// INIT
t.Setenv("TF_ENABLE_PLUGGABLE_STATE_STORAGE", "1")
stdout, stderr, err := tf.Run("init")
if err != nil {
t.Fatalf("unexpected init error: %s\nstderr:\n%s\nstdout:\n%s", err, stderr, stdout)
Expand Down Expand Up @@ -207,7 +206,7 @@ func TestPrimary_stateStore_workspaceCmd(t *testing.T) {
}

//// Init
_, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color")
_, stderr, err := tf.Run("init", "-plugin-dir=cache", "-no-color")
if err != nil {
t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr)
}
Expand Down Expand Up @@ -636,7 +635,7 @@ func TestPrimary_stateStore_providerCmds(t *testing.T) {
}

//// Init
_, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color")
_, stderr, err := tf.Run("init", "-plugin-dir=cache", "-no-color")
if err != nil {
t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr)
}
Expand Down
9 changes: 3 additions & 6 deletions internal/command/e2etest/primary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func TestPrimarySeparatePlan(t *testing.T) {
if len(stateResources) != 0 {
t.Errorf("wrong resources in state after destroy; want none, but still have:%s", spew.Sdump(stateResources))
}

}

func TestPrimaryChdirOption(t *testing.T) {
Expand Down Expand Up @@ -236,7 +235,6 @@ func TestPrimaryChdirOption(t *testing.T) {
}

func TestPrimary_stateStore(t *testing.T) {

if !canRunGoBuild {
// We're running in a separate-build-then-run context, so we can't
// currently execute this test which depends on being able to build
Expand Down Expand Up @@ -270,7 +268,7 @@ func TestPrimary_stateStore(t *testing.T) {
}

//// INIT
stdout, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color")
stdout, stderr, err := tf.Run("init", "-plugin-dir=cache", "-no-color")
if err != nil {
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
}
Expand Down Expand Up @@ -315,7 +313,6 @@ func TestPrimary_stateStore(t *testing.T) {
}

func TestPrimary_stateStore_planFile(t *testing.T) {

if !canRunGoBuild {
// We're running in a separate-build-then-run context, so we can't
// currently execute this test which depends on being able to build
Expand Down Expand Up @@ -348,7 +345,7 @@ func TestPrimary_stateStore_planFile(t *testing.T) {
}

//// INIT
stdout, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color")
stdout, stderr, err := tf.Run("init", "-plugin-dir=cache", "-no-color")
if err != nil {
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
}
Expand Down Expand Up @@ -432,7 +429,7 @@ func TestPrimary_stateStore_inMem(t *testing.T) {
//
// Note - the inmem PSS implementation means that the default workspace state created during init
// is lost as soon as the command completes.
stdout, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color")
stdout, stderr, err := tf.Run("init", "-plugin-dir=cache", "-no-color")
if err != nil {
t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
}
Expand Down
7 changes: 0 additions & 7 deletions internal/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ func (c *InitCommand) getProvidersFromState(ctx context.Context, state *states.S
// The calling code is expected to provide the previous locks (if any) and the two sets of locks determined from
// configuration and state data.
func (c *InitCommand) saveDependencyLockFile(previousLocks, configLocks, stateLocks *depsfile.Locks, flagLockfile string, view views.Init) (output bool, diags tfdiags.Diagnostics) {

// Get the combination of config and state locks
newLocks := c.mergeLockedDependencies(configLocks, stateLocks)

Expand Down Expand Up @@ -631,7 +630,6 @@ func (c *InitCommand) saveDependencyLockFile(previousLocks, configLocks, stateLo
// when a specific type of event occurs during provider installation.
// The calling code needs to provide a tfdiags.Diagnostics collection, so that provider installation code returns diags to the calling code using closures
func (c *InitCommand) prepareInstallerEvents(ctx context.Context, reqs providerreqs.Requirements, diags *tfdiags.Diagnostics, inst *providercache.Installer, view views.Init, initMsg views.InitMessageCode, reuseMsg views.InitMessageCode) *providercache.InstallerEvents {

// Because we're currently just streaming a series of events sequentially
// into the terminal, we're showing only a subset of the events to keep
// things relatively concise. Later it'd be nice to have a progress UI
Expand Down Expand Up @@ -758,7 +756,6 @@ func (c *InitCommand) prepareInstallerEvents(ctx context.Context, reqs providerr
),
))
}

},
QueryPackagesWarning: func(provider addrs.Provider, warnings []string) {
displayWarnings := make([]string, len(warnings))
Expand Down Expand Up @@ -1148,10 +1145,6 @@ Options:
Use this option more than once to include more than one
variables file.

-enable-pluggable-state-storage-experiment [EXPERIMENTAL]
A flag to enable an alternative init command that allows use of
pluggable state storage. Only usable with experiments enabled.

-create-default-workspace [EXPERIMENTAL]
This flag must be used alongside the -enable-pluggable-state-storage-
experiment flag with experiments enabled. This flag's value defaults
Expand Down
15 changes: 2 additions & 13 deletions internal/command/init_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,17 @@ func (c *InitCommand) run(initArgs *arguments.Init, view views.Init) int {

return 1
}
if !(c.Meta.AllowExperimentalFeatures && initArgs.EnablePssExperiment) && rootModEarly.StateStore != nil {
if !c.Meta.AllowExperimentalFeatures && rootModEarly.StateStore != nil {
// TODO(SarahFrench/radeksimko) - remove when this feature isn't experimental.
// This approach for making the feature experimental is required
// to let us assert the feature is gated behind an experiment in tests.
// See https://github.com/hashicorp/terraform/pull/37350#issuecomment-3168555619

detail := "Pluggable state store is an experiment which requires"
if !c.Meta.AllowExperimentalFeatures {
detail += " an experimental build of terraform"
}
if !initArgs.EnablePssExperiment {
if !c.Meta.AllowExperimentalFeatures {
detail += " and"
}
detail += " -enable-pluggable-state-storage-experiment flag"
}

diags = diags.Append(earlyConfDiags)
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Pluggable state store experiment not supported",
Detail: detail,
Detail: "Pluggable state store is an experiment which requires an experimental build of terraform",
Subject: &rootModEarly.StateStore.TypeRange,
})
view.Diagnostics(diags)
Expand Down
Loading
Loading