{"record":{"id":"d045e6d2f7c843b8","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","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: (.+?)","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/s3/backend_state.go#L54-L90","documentation":"Thrown in Backend.Workspaces (s3/backend_state.go:72) when the ListObjectsV2 paginator returns a *s3types.NoSuchBucket error. The configured bucket cannot be found by the caller's credentials in the resolved region. Terraform explicitly special-cases NoSuchBucket to give this actionable multi-line message.","triggerScenarios":"Typo in the bucket name; bucket lives in a different AWS account or region than the resolved credentials; AssumeRole resolved to the wrong account; bucket was deleted; bucket just created and not yet consistent.","commonSituations":"Wrong region in the backend block; AWS_PROFILE/AssumeRole pointing at the wrong account; bucket name with a stray suffix; Terraform run started immediately after bucket creation.","solutions":["Verify the bucket name and region in the backend config against `aws s3 ls`.","Confirm the caller identity (`aws sts get-caller-identity`) is in the account that owns the bucket.","Create the bucket if it is genuinely missing.","If just created, wait one to two minutes for S3 consistency and retry."],"exampleFix":"// before\n// backend \"s3\" { bucket = \"myco-tfstate\" region = \"us-east-1\" }\n\n// after (correct bucket/region)\n// backend \"s3\" { bucket = \"mycorp-terraform-state\" region = \"us-west-2\" }","handlingStrategy":"validation","validationCode":"// Validate the bucket exists and is in the expected region before init\n// out, err := s3Client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: aws.String(bucket)})\n// if err != nil { log.Fatalf(\"bucket missing/inaccessible: %v\", err) }\n// region := aws.ToString(out.BucketRegion)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `aws s3api head-bucket` in CI before `terraform init`.","Assert the assumed role's account id equals the bucket owner's.","Pin the region in the backend config explicitly."],"tags":["s3","aws","bucket","config","remote-state"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}