# Terraform: Error: creating S3 Bucket (my-bucket): BucketAlreadyOwnedByYou / EntityAlreadyExists: Role with name x already exists

**Code:** `Error creating resource: already exists (needs import)` · **Category:** Terraform · **Seen on:** Terraform, AWS

The resource exists outside Terraform's state (created manually or by another stack), so create fails.

## Meaning

Import it into state (`terraform import aws_iam_role.x role-name`, or an `import {}` block in 1.5+), then let Terraform manage it. Or use a different name, or remove the duplicate resource. For multi-environment name clashes add suffixes. After import run `plan` to reconcile differences.

## Common causes

- Resource created manually previously
- State lost/different backend/workspace
- Two stacks managing the same resource
- Name collision across environments
- Failed apply left a resource created but not in state

## Quick fix

1. `terraform import ADDRESS ID` (or `import { to = ..., id = "..." }`) then `terraform plan`
2. Use unique names per environment
3. Check you're using the right workspace/backend

## Detailed fix by platform

### Terraform

1. `terraform import aws_s3_bucket.logs my-logs-bucket`

## How to diagnose

1. **Exists** — In the cloud?
2. **State** — Tracked?
3. **Workspace** — Right?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/terraform/error-creating-resource-already-exists-import)
