Skip to content

Commit 0c05311

Browse files
committed
Pivot to creating the default workspace without prompts
This change was following discussions with Product
1 parent f992d80 commit 0c05311

File tree

2 files changed

+14
-54
lines changed

2 files changed

+14
-54
lines changed

internal/command/meta_backend.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,38 +1675,15 @@ func (m *Meta) stateStore_C_s(c *configs.StateStore, cHash int, backendSMgr *cli
16751675
return nil, diags
16761676

16771677
case ws == backend.DefaultStateName:
1678-
// Should we create the default state after prompting the user, or not?
1679-
if m.Input() {
1680-
// If input is enabled, we prompt the user before creating the default workspace.
1681-
input := m.UIInput()
1682-
desc := fmt.Sprintf("Terraform will create the %q workspace via state store %q.\n"+
1683-
"Only 'yes' will be accepted to approve.", backend.DefaultStateName, c.Type)
1684-
v, err := input.Input(context.Background(), &terraform.InputOpts{
1685-
Id: "approve",
1686-
Query: fmt.Sprintf("Workspace the %s workspace does not exit, would you like to create it?", backend.DefaultStateName),
1687-
Description: desc,
1688-
})
1689-
if err != nil {
1690-
diags = diags.Append(fmt.Errorf("Failed to confirm %s workspace creation: %w", backend.DefaultStateName, err))
1691-
return nil, diags
1692-
}
1693-
if v != "yes" {
1694-
diags = diags.Append(fmt.Errorf("Cancelled creation of the %s workspace", backend.DefaultStateName))
1695-
return nil, diags
1696-
}
1678+
// Users control if the default workspace is created through the -create-default-workspace flag (defaults to true)
1679+
if opts.CreateDefaultWorkspace {
16971680
m.createDefaultWorkspace(c, b)
16981681
} else {
1699-
// If input is disabled, we don't prompt before creating the default workspace.
1700-
// However this can be blocked with other flags present.
1701-
if opts.CreateDefaultWorkspace {
1702-
m.createDefaultWorkspace(c, b)
1703-
} else {
1704-
diags = diags.Append(&hcl.Diagnostic{
1705-
Severity: hcl.DiagWarning,
1706-
Summary: "The default workspace does not exist",
1707-
Detail: "Terraform has been configured to skip creation of the default workspace in the state store. This may cause issues in subsequent Terraform operations",
1708-
})
1709-
}
1682+
diags = diags.Append(&hcl.Diagnostic{
1683+
Severity: hcl.DiagWarning,
1684+
Summary: "The default workspace does not exist",
1685+
Detail: "Terraform has been configured to skip creation of the default workspace in the state store.",
1686+
})
17101687
}
17111688
default:
17121689
diags = diags.Append(err)

internal/command/meta_backend_test.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,39 +2085,26 @@ func Test_determineInitReason(t *testing.T) {
20852085
func TestMetaBackend_configureNewStateStore(t *testing.T) {
20862086
cases := map[string]struct {
20872087
// setup
2088-
isInitCommand bool
2089-
2090-
inputEnabled bool
2091-
inputText string
2092-
2088+
isInitCommand bool
20932089
createDefaultWorkspace bool
20942090
// assertions
20952091
expectedError string
20962092
expectDefaultWorkspaceExists bool
20972093
}{
2098-
"an init command prompts users for input when the default workspace needs to be created": {
2099-
inputEnabled: true,
2100-
createDefaultWorkspace: true,
2101-
inputText: "yes",
2102-
isInitCommand: true,
2103-
expectDefaultWorkspaceExists: true,
2104-
},
2105-
"an init command with input disabled will create the default workspace automatically": {
2106-
inputEnabled: false,
2094+
"an init command creates the default workspace by default": {
21072095
createDefaultWorkspace: true,
21082096
isInitCommand: true,
21092097
expectDefaultWorkspaceExists: true,
21102098
},
2111-
"an init command with input disabled and the flag -create-default-workspace=false will not make the default workspace": {
2112-
inputEnabled: false,
2099+
"an init command with the flag -create-default-workspace=false will not make the default workspace": {
21132100
createDefaultWorkspace: false,
21142101
isInitCommand: true,
21152102
expectDefaultWorkspaceExists: false,
21162103
},
2117-
// "during a non-init command, the command ends in with an error telling the user to run an init command": {
2118-
// isInitCommand: false,
2119-
// expectedError: "State store initialization required, please run \"terraform init\": Reason: Initial configuration of the requested state_store \"foo_bar\" in provider foo (\"registry.terraform.io/my-org/foo\")",
2120-
// },
2104+
"during a non-init command, the command ends in with an error telling the user to run an init command": {
2105+
isInitCommand: false,
2106+
expectedError: "State store initialization required, please run \"terraform init\": Reason: Initial configuration of the requested state_store \"foo_bar\" in provider foo (\"registry.terraform.io/my-org/foo\")",
2107+
},
21212108
}
21222109

21232110
for tn, tc := range cases {
@@ -2129,10 +2116,6 @@ func TestMetaBackend_configureNewStateStore(t *testing.T) {
21292116
// Setup the meta
21302117
m := testMetaBackend(t, nil)
21312118
m.AllowExperimentalFeatures = true
2132-
m.input = tc.inputEnabled
2133-
if tc.inputEnabled {
2134-
defer testInteractiveInput(t, []string{tc.inputText})()
2135-
}
21362119

21372120
// Get the state store's config
21382121
mod, loadDiags := m.loadSingleModule(td)

0 commit comments

Comments
 (0)