# Resource Groups

> Organize related resources and schedule them together with execution tiers and ordering for dependency-aware start and stop.

Source: https://zop.dev/developer-docs/core-concepts/resource-groups

---

Resource groups let you organize related resources and schedule them together with defined execution ordering.

## Overview

A resource group is a logical collection of cloud resources that should be managed together. When a group is attached to a schedule, all its members are started/stopped according to their execution tier and order — ensuring dependencies are respected.

**Tip**

Resources within a group are organized into execution tiers. All resources in tier 1 are processed first, then tier 2, and so on. Within a tier, the execution order determines the sequence. This is ideal for dependency chains (e.g., database → cache → application server).

## Create Resource Group

### POST /resource-groups

Create a new resource group.

```bash title="Request"
curl -X POST https://zopnight.com/api/resource-groups \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Backend Stack",
    "description": "Database, cache, and app servers for the backend"
  }'
```

```json title="Response"
{
  "data": {
    "id": "grp_abc123",
    "name": "Backend Stack",
    "description": "Database, cache, and app servers for the backend",
    "members": [],
    "createdBy": "user@company.com",
    "createdAt": "2025-01-15T10:30:00Z",
    "updatedAt": "2025-01-15T10:30:00Z"
  }
}
```

## List Resource Groups

### GET /resource-groups

List all resource groups.

## Get Resource Group

### GET /resource-groups/{groupID}

Get a resource group with its members.

## Get Group Schedules

### GET /resource-groups/{groupID}/schedules

List all schedules attached to a resource group.

## Update Resource Group

### PUT /resource-groups/{groupID}

Update group name or description.

```bash title="Request"
curl -X PUT https://zopnight.com/api/resource-groups/grp_abc123 \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Full Backend Stack",
    "description": "Updated description"
  }'
```

## Delete Resource Group

### DELETE /resource-groups/{groupID}

Delete a resource group. Schedule attachments are also removed.

## Add Member

### POST /resource-groups/{groupID}/resources/{resourceID}

Add a resource to the group.

Members are added with a default execution tier and order. Use the update sequence endpoint to configure execution ordering.

## Update Execution Order

### PATCH /resource-groups/{groupID}/resources/{resourceID}/sequence

Update the execution tier and order for a group member.

```bash title="Request"
curl -X PATCH https://zopnight.com/api/resource-groups/grp_abc123/resources/res_001/sequence \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "executionTier": "tier-1",
    "executionOrder": 1
  }'
```

Example ordering for a backend stack:

| Resource | Tier | Order | Starts |
|---|---|---|---|
| PostgreSQL RDS | `tier-1` | 1 | First |
| Redis ElastiCache | `tier-1` | 2 | Second |
| App Server EC2 | `tier-2` | 1 | After tier 1 completes |
| Worker EC2 | `tier-2` | 2 | After app server |

## Remove Member

### DELETE /resource-groups/{groupID}/resources/{resourceID}

Remove a resource from the group.

## Group Member Object

| Field | Type | Description |
|---|---|---|
| `id` | string | Membership ID |
| `resourceUID` | string | Cloud provider resource UID |
| `resourceName` | string | Resource display name |
| `resourceType` | string | Resource type (e.g., aws-ec2) |
| `provider` | string | Cloud provider |
| `cloudAccountID` | string | Connected cloud account ID |
| `region` | string | Cloud region |
| `executionTier` | string | Execution tier for ordering (e.g., tier-1, tier-2) |
| `executionOrder` | integer | Order within the tier |
