{"record":{"id":"c30b1b6fa1ab2c02","repo":"hashicorp/terraform","slug":"the-state-is-already-locked-by-another-terraform-c","errorCode":null,"errorMessage":"the state is already locked by another terraform client","messagePattern":"the state is already locked by another terraform client","errorType":"console","errorClass":"LockError","httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/kubernetes/client.go","lineNumber":285,"sourceCode":"\t\t\treturn \"\", err\n\t\t} else {\n\t\t\treturn info.ID, nil\n\t\t}\n\t}\n\n\tif lease.Spec.HolderIdentity != nil {\n\t\tif *lease.Spec.HolderIdentity == info.ID {\n\t\t\treturn info.ID, nil\n\t\t}\n\n\t\tcurrentLockInfo, err := c.getLockInfo(lease)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\tlockErr := &statemgr.LockError{\n\t\t\tInfo: currentLockInfo,\n\t\t\tErr:  errors.New(\"the state is already locked by another terraform client\"),\n\t\t}\n\t\treturn \"\", lockErr\n\t}\n\n\tlease.Spec.HolderIdentity = pointer.StringPtr(info.ID)\n\tsetLockInfo(lease, info.Marshal())\n\t_, err = c.kubernetesLeaseClient.Update(ctx, lease, metav1.UpdateOptions{})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn info.ID, err\n}\n\nfunc (c *RemoteClient) Unlock(id string) error {\n\tleaseName, err := c.createLeaseName()\n\tif err != nil {\n\t\treturn err","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/kubernetes/client.go#L267-L303","documentation":"In the NestingMap case, Computed cannot be combined with MinItems > 0. In practice the preceding check (error 11) already forces MinItems to 0 for NestingMap, so this branch is effectively unreachable, but it guards against any future relaxation where MinItems could be nonzero while the block is computed.","triggerScenarios":"Theoretically a NestingMap with Computed: true and MinItems > 0; in current code the NestingMap MinItems!=0 check at line 111 fires first. Guard at internal_validate.go:114 is `blockS.MinItems > 0 && blockS.Computed`.","commonSituations":"Not independently reachable today; you will first hit 'MinItems and MaxItems must both be 0 in NestingMap mode'. Treat any encounter as a sign that the NestingMap count constraint was bypassed.","solutions":["Ensure MinItems is 0 for NestingMap (resolves the upstream error 11 first).","If Computed is required on a map-shaped block, keep MinItems/MaxItems at 0.","Switch to NestingList/NestingSet if both a min count and Computed are genuinely needed (then see error 10)."],"exampleFix":"// before\n\"computed_map\": {\n  Nesting: configschema.NestingMap,\n  MinItems: 1,\n  Block: configschema.Block{Computed: true},\n},\n// after\n\"computed_map\": {\n  Nesting: configschema.NestingMap,\n  MinItems: 0,\n  MaxItems: 0,\n  Block: configschema.Block{Computed: true},\n},","handlingStrategy":"validation","validationCode":"// Defensive: NestingMap should not combine Computed with MinItems > 0.\nfunc validMapComputed(nb *configschema.NestedBlock) bool {\n    return nb.Nesting != configschema.NestingMap || !(nb.Computed && nb.MinItems > 0)\n}","typeGuard":"func mapComputedOk(computed bool, min int) bool { return !computed || min == 0 }","tryCatchPattern":null,"preventionTips":["Keep NestingMap MinItems at 0 (also required by error 11).","Treat any encounter of this message as a sign the upstream count check was bypassed.","Prefer NestingList/NestingSet if you need both a min count and Computed."],"tags":["schema-validation","configschema","nestingmap","computed","minitems","dead-code","provider-schema"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}