# Delete an IAM user

Delete an IAM user or service account, with its group memberships, role assignments and policy attachments.

Replace user-id with the IAM user's id.

**Warning:**
Deleting cannot be undone. Anything that authenticates as the user, such as its access keys, loses
access at once.

Deleting a person's IAM user also removes the person from the organization, exactly as removing
the member does: the membership is suspended, their console sessions end and the apps they
connected to the organization are disconnected. To take a person's access away while keeping their
IAM user as a record, remove them from the organization instead; see
[Manage members](manage-members.md).

## Prerequisites

- Permission for `iam:DeleteUser` on the user. For a person's IAM user, also `iam:RemoveMember`.
- For the console, also `iam:ListUsers` to open **Users**, and `iam:GetUser` on the user: its page
  answers 404 without it.

## Delete the user

**Console**
1. Open **Identity**, choose **Users**, then the user.
2. Choose **Danger zone**, then **Delete IAM user**.
3. Type the user name and confirm.

**CLI**
```sh
dcloud iam users delete user-id
```

**API**
```http
DELETE /iam/api/users/3f8b6c2e-1d4a-4b7e-9c2f-5a6b7c8d9e0f
```

**Terraform**
Remove the `dcloud_iam_user` resource from your configuration and apply.

## Result

The user, its group memberships, its role assignments and its policy attachments are gone. The
policies themselves stay. When the user signed in to the console with a user name, that sign-in is
deleted with it.

## If the deletion is refused

- 404 `IAM user not found` for an id that is not an IAM user of your organization.
- 409 `This is the organization owner's IAM user and cannot be deleted`: the owner holds
  `AdministratorAccess` through it.
- 403 for a person's IAM user when you have `iam:DeleteUser` but not `iam:RemoveMember`. Nothing is
  changed.

## Related

- [Create an IAM user](create-an-iam-user.md)
- `iam.users.delete` · `dcloud iam users delete` · `dcloud_iam_user`
