{"record":{"id":"6a78ce9a78f9892a","repo":"hashicorp/terraform","slug":"file-exceeds-maximum-part-count","errorCode":null,"errorMessage":"file exceeds maximum part count","messagePattern":"file exceeds maximum part count","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oci/multipart_upload.go","lineNumber":198,"sourceCode":"\t\t}\n\t\tsourceBlocks[i] = objectStorageSourceBlock{\n\t\t\tsection:     io.NewSectionReader(bytes.NewReader(m.Data), start, end-start),\n\t\t\tblockNumber: common.Int(i + 1),\n\t\t}\n\t}\n\treturn sourceBlocks, nil\n}\n\n/*\nSplitSizeToOffsetsAndLimits splits a file size into chunks based on DefaultFilePartSize.\nReturns the byte offsets and byte limits for each chunk.\nReturns an error if the size exceeds MaxCount parts.\n*/\nfunc SplitSizeToOffsetsAndLimits(size int64) ([]int64, int64, error) {\n\tpartSize := DefaultFilePartSize\n\ttotalParts := (size + partSize - 1) / partSize\n\tif totalParts > MaxCount {\n\t\treturn nil, 0, fmt.Errorf(\"file exceeds maximum part count\")\n\t}\n\toffsets := make([]int64, totalParts)\n\tfor i := range offsets {\n\t\toffsets[i] = int64(i) * partSize\n\t}\n\treturn offsets, partSize, nil\n}\n\nfunc (ctx *objectStorageMultiPartUploadContext) uploadPartsWorker() {\n\tfor block := range ctx.sourceBlocks {\n\t\tbuffer := make([]byte, block.section.Size())\n\t\t_, err := block.section.Read(buffer)\n\t\tif err != nil {\n\t\t\tctx.errChan <- fmt.Errorf(\"error reading source block %d: %w\", block.blockNumber, err)\n\t\t\treturn\n\t\t}\n\t\ttmpLength := int64(len(buffer))\n\t\tsum := md5.Sum(buffer)","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oci/multipart_upload.go#L180-L216","documentation":"Raised in SplitSizeToOffsetsAndLimits when the computed part count exceeds MaxCount (10000). This is the root cause error that 317 and 312 ultimately wrap. At the default DefaultFilePartSize of 128MiB, it triggers for payloads larger than 10000 * 128MiB (~1.28 TiB), making a multipart upload impossible under the configured part size.","triggerScenarios":"SplitSizeToOffsetsAndLimits computes totalParts = (size + partSize - 1) / partSize (multipart_upload.go:196) and totalParts > MaxCount (10000). Concretely size > 10000 * DefaultFilePartSize.","commonSituations":"A terraform.tfstate exceeding ~1.28 TiB due to runaway resources, embedded blobs, or synthetic test data; DefaultFilePartSize lowered by mistake, shrinking the per-part size and inflating part count.","solutions":["Reduce the state file size below the threshold (split states, prune, externalize blobs).","Raise DefaultFilePartSize to reduce totalParts (must remain within OCI's max part size and keep under MaxCount).","If DefaultFilePartSize was customized, restore it to 128MiB or higher so a given size yields fewer parts.","Investigate why the state grew so large; normal Terraform states are orders of magnitude smaller."],"exampleFix":"// before: a lowered part size inflates part count over MaxCount\nvar DefaultFilePartSize int64 = 10 * 1024 * 1024 // 10MiB -> 10000 parts at only ~98GiB\n// after: restore default so MaxCount covers ~1.28TiB\nvar DefaultFilePartSize int64 = 128 * 1024 * 1024","handlingStrategy":"validation","validationCode":"// Guard the splitter explicitly:\ntotalParts := (size + partSize - 1) / partSize\nif totalParts > MaxCount {\n    return nil, 0, fmt.Errorf(\"file exceeds maximum part count\")\n}","typeGuard":null,"tryCatchPattern":"if totalParts > MaxCount {\n    return nil, 0, fmt.Errorf(\"file exceeds maximum part count\")\n}","preventionTips":["Keep state far below ~1.28 TiB.","Do not lower DefaultFilePartSize below 128MiB without rechecking MaxCount.","Externalize large data out of tfstate."],"tags":["oci","multipart-upload","size-limit","max-count","configuration","terraform-state"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}