{"record":{"id":"69e93064e83ad3f2","repo":"hashicorp/terraform","slug":"s3-bucket-q-does-not-exist-the-referenced-s3-bu","errorCode":null,"errorMessage":"S3 bucket %q does not exist.\n\nThe referenced S3 bucket must have been previously created. If the S3 bucket\nwas created within the last minute, please wait for a minute or two and try\nagain.\n\nError: %s\n","messagePattern":"S3 bucket %q does not exist\\.\n\nThe referenced S3 bucket must have been previously created\\. If the S3 bucket\nwas created within the last minute, please wait for a minute or two and try\nagain\\.\n\nError: (.+?)\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/s3/backend_state.go","lineNumber":72,"sourceCode":"\t)\n\n\tparams := &s3.ListObjectsV2Input{\n\t\tBucket:  aws.String(b.bucketName),\n\t\tPrefix:  aws.String(prefix),\n\t\tMaxKeys: aws.Int32(maxKeys),\n\t}\n\n\twss := []string{backend.DefaultStateName}\n\n\tctx, baselog := baselogging.NewHcLogger(ctx, log)\n\tctx = baselogging.RegisterLogger(ctx, baselog)\n\n\tpages := s3.NewListObjectsV2Paginator(b.s3Client, params)\n\tfor pages.HasMorePages() {\n\t\tpage, err := pages.NextPage(ctx)\n\t\tif err != nil {\n\t\t\tif IsA[*s3types.NoSuchBucket](err) {\n\t\t\t\treturn nil, diags.Append(fmt.Errorf(errS3NoSuchBucket, b.bucketName, err))\n\t\t\t}\n\t\t\tif foo, ok := As[smithy.APIError](err); b.workspaceKeyPrefix == defaultWorkspaceKeyPrefix && ok && foo.ErrorCode() == \"AccessDenied\" {\n\t\t\t\tlog.Warn(\"Unable to list non-default workspaces\", \"err\", err.Error())\n\t\t\t\treturn wss[:1], nil\n\t\t\t}\n\t\t\treturn nil, diags.Append(fmt.Errorf(\"Unable to list objects in S3 bucket %q with prefix %q: %w\", b.bucketName, prefix, err))\n\t\t}\n\n\t\tfor _, obj := range page.Contents {\n\t\t\tws := b.keyEnv(aws.ToString(obj.Key))\n\t\t\tif ws != \"\" {\n\t\t\t\twss = append(wss, ws)\n\t\t\t}\n\t\t}\n\t}\n\n\tsort.Strings(wss[1:])\n\treturn wss, diags","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/s3/backend_state.go#L54-L90","documentation":"Thrown by Backend.Workspaces in the S3 state backend when ListObjectsV2 paginator's NextPage returns an error that IsA[*s3types.NoSuchBucket] matches. The errS3NoSuchBucket template explains the bucket must have been pre-created and that very-recent creation may need a minute to propagate. This is a config/existence failure, not transient.","triggerScenarios":"s3.NewListObjectsV2Paginator(...).NextPage(ctx) errors and the error type-asserts to *s3types.NoSuchBucket. The bucket b.bucketName does not exist in the configured account/region, or the credentials point at the wrong account.","commonSituations":"Typo in `bucket` in the S3 backend block; bucket in a different region than configured; bucket in a different AWS account and the principal has no cross-account access; bucket literally not yet created; wrong profile/role assumed so the caller sees a different account.","solutions":["Verify the bucket exists: `aws s3api head-bucket --bucket <name>` with the same credentials/profile OpenTofu uses.","Check the `region` in the backend block matches the bucket's region.","Confirm the AWS profile/role assumed by OpenTofu is the one that owns the bucket.","If the bucket was just created, wait 60-120s for global consistency and re-run `tofu init`."],"exampleFix":"# before\nterraform {\n  backend \"s3\" {\n    bucket = \"my-state-bukcet\"  # typo\n  }\n}\n# after\nterraform {\n  backend \"s3\" {\n    bucket = \"my-state-bucket\"\n  }\n}","handlingStrategy":"validation","validationCode":"// preflight: head the bucket with the exact credentials tofu will use\nctx := context.Background()\n_, err := s3Client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: aws.String(bucketName)})\nif err != nil { return fmt.Errorf(\"bucket %s not visible: %w\", bucketName, err) }","typeGuard":"func isNoSuchBucketErr(err error) bool {\n    var nsb *s3types.NoSuchBucket\n    return errors.As(err, &nsb) || strings.Contains(err.Error(), \"NoSuchBucket\")\n}","tryCatchPattern":null,"preventionTips":["Pre-create the state bucket before `tofu init`.","Pin backend `bucket` and `region` via a config lint step.","Use `aws s3api head-bucket` as a CI preflight with the same profile."],"tags":["s3","aws","no-such-bucket","config","workspaces"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}