{"record":{"id":"0b118ad563d60459","repo":"hashicorp/terraform","slug":"cannot-delete-default-state","errorCode":null,"errorMessage":"cannot delete default state","messagePattern":"cannot delete default state","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/local/backend.go","lineNumber":248,"sourceCode":"}\n\n// DeleteWorkspace removes a workspace.\n//\n// The \"default\" workspace cannot be removed.\nfunc (b *Local) DeleteWorkspace(name string, force bool) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\t// If we have a backend handling state, defer to that.\n\tif b.Backend != nil {\n\t\treturn b.Backend.DeleteWorkspace(name, force)\n\t}\n\n\tif name == \"\" {\n\t\treturn diags.Append(errors.New(\"empty state name\"))\n\t}\n\n\tif name == backend.DefaultStateName {\n\t\treturn diags.Append(errors.New(\"cannot delete default state\"))\n\t}\n\n\tdelete(b.states, name)\n\terr := os.RemoveAll(filepath.Join(b.stateWorkspaceDir(), name))\n\tif err != nil {\n\t\treturn diags.Append(fmt.Errorf(\"error deleting workspace %s: %w\", name, err))\n\t}\n\n\treturn diags\n}\n\nfunc (b *Local) StateMgr(name string) (statemgr.Full, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\t// If we have a backend handling state, delegate to that.\n\tif b.Backend != nil {\n\t\treturn b.Backend.StateMgr(name)\n\t}","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/local/backend.go#L230-L266","documentation":"In NestingSingle mode MinItems and MaxItems must be equal, because NestingSingle permits exactly zero or one instance. Mismatched values (e.g. MinItems=0, MaxItems=1) are ambiguous and rejected. This is checked first in the NestingSingle case before the 0-or-1 range check.","triggerScenarios":"A NestedBlock with Nesting: NestingSingle where MinItems != MaxItems (e.g. MinItems: 0, MaxItems: 1). Guard at internal_validate.go:76 is `blockS.MinItems != blockS.MaxItems`.","commonSituations":"Treating NestingSingle like NestingList and trying to set an optional/required pair; copying NestingList defaults into a NestingSingle block.","solutions":["If the block is optional, set both MinItems: 0 and MaxItems: 0.","If the block is required, set both MinItems: 1 and MaxItems: 1.","Switch to NestingList/NestingSet if you genuinely need a min/max range."],"exampleFix":"// before\n\"settings\": { Nesting: configschema.NestingSingle, MinItems: 0, MaxItems: 1 },\n// after (optional single)\n\"settings\": { Nesting: configschema.NestingSingle, MinItems: 0, MaxItems: 0 },","handlingStrategy":"validation","validationCode":"// For NestingSingle, require equal counts.\nfunc validSingleCounts(nb *configschema.NestedBlock) bool {\n    return nb.Nesting != configschema.NestingSingle || nb.MinItems == nb.MaxItems\n}","typeGuard":"func singleCountsMatch(min, max int) bool { return min == max }","tryCatchPattern":null,"preventionTips":["For NestingSingle use (0,0) for optional or (1,1) for required.","Avoid copying NestingList min/max values into a NestingSingle block.","Prefer NestingList when you need a min/max range."],"tags":["schema-validation","configschema","nestingsingle","minitems","maxitems","provider-schema"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}