# Getting started with Identity and Access Management

Create a group with read-only compute access, put a new IAM user in it, check what the user may do, and clean up.

In about ten minutes you give a group the managed policy `Ec2ReadOnlyAccess`, add an IAM user
called alice to it, and confirm with the policy simulator that she may list instances but not
terminate them. Nothing here is charged. Replace org-EXAMPLE1234 with your organization id,
and the ids the CLI prints where the commands ask for them.

## Prerequisites

- You are the organization owner, or your policies allow `iam:CreateGroup`, `iam:AttachGroupPolicy`,
  `iam:CreateUser`, `iam:AddUserToGroup`, `iam:SimulatePrincipalPolicy`, `iam:DeleteUser` and
  `iam:DeleteGroup`.
- For the console, also `iam:ListGroups`, `iam:GetGroup`, `iam:ListUsers` and `iam:GetUser` to open
  the lists and the pages (a group's or user's page answers 404 without the `Get` action).
- For the CLI, also `iam:ListPolicies` to find the policy's id.
- For the CLI: `dcloud auth login` has signed you in; see [Sign in the CLI](sign-in-the-cli.md).

## Step 1: Create a group

**Console**
1. Open **Identity**, then choose **Groups**.
2. Choose **Create group**, enter developers as the group name, and choose **Create group**.
   The group's page opens.

**CLI**
```sh
dcloud iam groups create --name developers --description "Read-only compute"
```

The answer holds the group's `id`.

## Step 2: Attach a managed policy to the group

**Console**
1. On the group's page, choose **Permissions**.
2. Open the policy list, choose `Ec2ReadOnlyAccess`, then choose **Attach**.

**CLI**
Find the policy's id, then attach it:

```sh
dcloud iam policies list
dcloud iam groups attach-policy group-id --policy-id policy-id
```

## Step 3: Create an IAM user and add it to the group

**Console**
1. Choose **Users**, then **Create user**.
2. For **Username**, enter alice. Leave **Type** at **User**.
3. Choose **Create user**. The user's page opens.
4. Go back to the group developers and choose **Members**.
5. Open the user list, choose alice, then choose **Add**.

**CLI**
```sh
dcloud iam users create --username alice
dcloud iam groups add-member group-id --iam-user-id user-id
```

## Step 4: Check what the user may do

**Console**
1. Choose **Policy simulator**.
2. For **Who**, choose alice. For **Action**, search for and choose `ec2:DescribeInstances`. For **Resource**,
   enter `rn:ews:de1:org-EXAMPLE1234:ec2:*`.
3. Choose **Simulate**. The answer is **Allowed**, through the group developers.
4. Choose `ec2:TerminateInstances` for **Action** and choose **Simulate** again. The answer is
   **Implicitly denied**: no statement allows it.

**CLI**
```sh
dcloud iam policies simulate --action ec2:DescribeInstances \
  --resource 'rn:ews:de1:org-EXAMPLE1234:ec2:*' \
  --principal '{"type":"user","id":"user-id"}'
```

The answer's `decision` is `allowed`. With `--action ec2:TerminateInstances` it is
`implicitly_denied`.

## Clean up

Deleting the user removes its group membership; deleting the group detaches its policy. The
managed policy itself stays.

**Console**
1. Open the user alice, choose **Danger zone**, then **Delete IAM user**. Type the user name
   and confirm.
2. Open the group developers, choose **Danger zone**, then **Delete group**. Type the group
   name and confirm.

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

## Next steps

- [Invite a person](invite-a-person.md): give a colleague access with their own email address.
- [Create a policy](create-a-policy.md): write a policy of your own.
- [Grant access to one resource](grant-access-to-one-resource.md)
