* refactor: Stop Terraform creating the default workspace during init when using PSS
This is part of reconciling how in the past backends always reported that the default backend existed, even when it didn't. We want state stores to report reality only, so we need to let Terraform handle the discrepancy. Prior to this commit we handled it by making reality match the old lie that the default workspace always exists. After this commit we're just embracing Terraform working with truthful information.
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")
"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.
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Cannot use -create-default-workspace flag without experiments enabled",
"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.
"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).",
// 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
// Users control if the default workspace is created through the -create-default-workspace flag (defaults to true)
ifopts.CreateDefaultWorkspace{
diags=diags.Append(m.createDefaultWorkspace(c,b))
if!diags.HasErrors(){
// Report workspace creation to the view
view:=views.NewInit(vt,m.View)
view.Output(views.DefaultWorkspaceCreatedMessage)
}
}else{
diags=diags.Append(&hcl.Diagnostic{
Severity:hcl.DiagWarning,
Summary:"The default workspace does not exist",
Detail:"Terraform has been configured to skip creation of the default workspace in the state store. To create it, either remove the `-create-default-workspace=false` flag and re-run the 'init' command, or create it using a 'workspace new' command",
})
}
// If the default workspace is selected, no workspaces existing _may_ be expected.
// It's valid for the default workspace's state to not be created until the first apply takes place.
// However, it could be that the user is configuring their working directory for the first time but
// they expect pre-existing state to be in the store from previous actions. In that case, the user
// should realise their mistake once they generate a plan.
//
// So here, we will just ignore the error.
}else{
// User needs to run a `terraform workspace new` command to create the missing custom workspace.
diags=append(diags,tfdiags.Sourceless(
@ -2813,35 +2821,6 @@ To make the initial dependency selections that will initialize the dependency lo
returnpVersion,diags
}
// createDefaultWorkspace receives a backend made using a pluggable state store, and details about that store's config,
// and persists an empty state file in the default workspace. By creating this artifact we ensure that the default
// workspace is created and usable by Terraform in later operations.
diags=diags.Append(fmt.Errorf("Failed to create a state manager for state store %q in provider %s (%q). This is a bug in Terraform and should be reported: %w",