# Edit or delete a policy

Change a custom policy's document, name or description, or delete the policy and detach it everywhere.

Only custom policies can be changed. Managed policies are maintained by Deutsche Cloud; to change what
one grants, copy its document into a custom policy (see [Create a policy](create-a-policy.md)).
Replace policy-id with the policy's id.

## Prerequisites

- To edit, `iam:UpdatePolicy` on the policy. To delete, `iam:DeletePolicy`.
- In the console, also `iam:ListPolicies` to see **Policies** and `iam:GetPolicy` on the policy to
  open it (without it the page is not found).

## Edit the document

A change applies to every user, group and role that holds the policy, from their next request on.

**Console**
1. Open **Identity**, choose **Policies**, then the policy.
2. Choose **Document**, then **Edit**. A managed policy has no **Edit**.
3. Change the JSON, then choose **Save document**. The document is checked as you type; an
   unchanged document is not saved.

The console changes the document only; the name and the description change through the CLI, the API
or Terraform.

**CLI**
```sh
dcloud iam policies update policy-id \
  --document '{"Version":"2024-01-01","Statement":[{"Effect":"Allow","Action":["s3:GetObject"],"Resource":["*"]}]}'
```

`--name` and `--description` change the name and the description.

**API**
```http
PATCH /iam/api/policies/9b2e4c1a-7d3f-4e8a-b6c5-0a1b2c3d4e5f
{ "description": "Read objects in every bucket" }
```

**Terraform**
Change `document` on the `dcloud_iam_policy` resource and apply.

The new document is checked the same way as at creation; see
[Create a policy](create-a-policy.md#if-the-policy-is-refused).

## Delete the policy

**Warning:**
Every user, group and role holding the policy loses its permissions the moment it is deleted.

**Console**
1. Open the policy, then choose **Danger zone**.
2. Choose **Delete policy**, type the policy name, and confirm.

**CLI**
```sh
dcloud iam policies delete policy-id
```

**API**
```http
DELETE /iam/api/policies/9b2e4c1a-7d3f-4e8a-b6c5-0a1b2c3d4e5f
```

**Terraform**
Remove the `dcloud_iam_policy` resource and its attachments from your configuration and apply.

Deleting detaches the policy from everyone who held it.

## If the change is refused

- 400 `Cannot modify a managed policy` or `Cannot delete a managed policy`.
- 400 `Invalid policy document: …` for a document that does not pass the checks.

## Related

- [Policy documents](policy-documents.md)
- [Test access with the policy simulator](test-access-with-the-simulator.md)
- `iam.policies.update` · `iam.policies.delete` · `dcloud_iam_policy`
