# Resources

> Cloud infrastructure components discovered across connected cloud accounts. Statuses, Kubernetes workload discovery, list and refresh APIs, filters, and the resource object schema.

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

---

Resources are cloud infrastructure components (VMs, databases, clusters, etc.) discovered across your connected cloud accounts.

## Overview

When you connect a cloud account, ZopNight's discoverer service scans for resources across all enabled regions. Each resource is classified by type, tagged as schedulable or inventory-only, and stored with its cloud metadata.

**Info**

Each resource has a `uid` field containing the cloud provider's native resource identifier (e.g., `i-0abc123def456` for AWS EC2, or `projects/my-project/zones/us-central1-a/instances/vm1` for GCP Compute). This UID is used to reference resources in schedules, actions, and other operations.

**Info**

EKS and GKE clusters expose their workload children — `aws-eks-deployment`, `aws-eks-statefulset`, `aws-eks-cronjob` (and the GCP equivalents) — for inventory and topology. Azure Databricks exposes `azure-databricks-cluster`, `azure-databricks-instance-pool`, and `azure-databricks-warehouse` as children of the workspace. Children inherit `parentUID` from the parent cluster/workspace.

## Resource Statuses

| Status | Description |
|---|---|
| `running` | Resource is active and running |
| `stopped` | Resource has been stopped |
| `starting` | Resource is transitioning to running state |
| `stopping` | Resource is transitioning to stopped state |
| `pending` | Resource state is being determined |

## Kubernetes workload discovery

ZopNight discovers what runs *inside* your clusters, not just the cluster nodes. EKS, GKE, and AKS expose a uniform set of workload children — listed alongside compute and network resources, schedulable where the underlying API allows it.

| Category | Resource types |
|---|---|
| **Workloads** | `deployment, statefulset, daemonset, job, cronjob, replicaset` |
| **Services & networking** | `service, ingress, networkpolicy` |
| **Configuration** | `configmap, secret, serviceaccount` |
| **Storage** | `persistentvolume, persistentvolumeclaim, storageclass` |
| **Autoscaling** | `horizontalpodautoscaler, verticalpodautoscaler` |
| **Cluster** | `namespace, node, pod, role, rolebinding, clusterrole, clusterrolebinding` |

Cluster types — `aws-eks`, `gcp-gke`, `azure-aks` — gain a detail page that lists workloads, breaks down nodes, filters by namespace, and renders pod- and workload-level CPU/memory metrics from the cluster's metrics backend.

**Info**

Resources and Recommendations pages now show a DB-backed sync status header — last successful sync timestamp per provider/service, per cloud account.

## List Resources

### GET /resources

List all discovered resources with filtering and pagination.

#### Query Parameters

| Parameter | Type | Description |
|---|---|---|
| `search` | string | Search by resource name or UID |
| `type` | string | Filter by resource type (e.g., aws-ec2, gcp-compute) |
| `provider` | string | Filter by cloud provider (aws, gcp, azure) |
| `status` | string | Filter by status (running, stopped, etc.) |
| `region` | string | Filter by cloud region |
| `schedulable` | boolean | Filter by schedulable capability |
| `page` | integer | Page number (default: 1) |
| `limit` | integer | Items per page (default: 20) |
| `sort_by` | string | Sort field (name, type, status, provider) |
| `sort_order` | string | asc or desc |

```bash title="Example"
curl "https://zopnight.com/api/resources?provider=aws&type=aws-ec2&status=running&limit=10" \
  -H "Authorization: Bearer <token>"
```

```json title="Response"
{
  "data": [
    {
      "id": "res_001",
      "name": "web-server-prod",
      "uid": "i-0abc123def456",
      "type": "aws-ec2",
      "instanceType": "t3.medium",
      "region": "us-east-1",
      "status": "running",
      "cloudAccountID": "ca_abc123",
      "cloudAccountName": "Production AWS",
      "provider": "aws",
      "schedulable": true,
      "tags": {
        "Environment": "production",
        "Team": "platform"
      },
      "createdAt": "2025-01-15T10:30:00Z",
      "updatedAt": "2025-01-20T08:00:00Z"
    }
  ]
}
```

## Get Resource

### GET /resources/{resourceID}

Get detailed information about a specific resource.

## Get Resources by IDs

### GET /resources/by-ids

Fetch multiple resources by their IDs in a single request.

```bash title="Example"
curl "https://zopnight.com/api/resources/by-ids?ids=res_001,res_002,res_003" \
  -H "Authorization: Bearer <token>"
```

## Get Resources by UIDs

Look up resources by their cloud-native UIDs (e.g., AWS instance IDs, GCP self-link paths, Azure resource IDs). Useful when you have UIDs from cost data, recommendations, or topology and need the corresponding ZopNight resource records.

### GET /resources/by-uids

Fetch resources by cloud UIDs (query string).

```bash title="Example"
curl "https://zopnight.com/api/resources/by-uids?uids=i-0abc,i-0def" \
  -H "Authorization: Bearer <token>"
```

### POST /resources/by-uids

Fetch resources by cloud UIDs (large lists in JSON body).

```bash title="Request"
curl -X POST https://zopnight.com/api/resources/by-uids \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{ "uids": ["i-0abc", "i-0def", "vm-prod-1"] }'
```

## Count Resources

### GET /resources/count

Total resource count for the org. Accepts the same filters as the list endpoint.

## Discovery Summary

### GET /resources/discovery-summary

Per-provider discovery rollup — schedulable counts, scanned regions, and last-success timestamps. Used by the dashboard hero.

```json title="Response"
{
  "data": {
    "totalResources": 1284,
    "schedulableResources": 342,
    "providers": [
      { "provider": "aws", "resources": 821, "lastSyncedAt": "2026-04-29T05:00:00Z" },
      { "provider": "gcp", "resources": 287, "lastSyncedAt": "2026-04-29T05:01:30Z" },
      { "provider": "azure", "resources": 176, "lastSyncedAt": "2026-04-29T05:02:10Z" }
    ]
  }
}
```

## Access Check

### GET /resources/{id}/access

Check whether the stored cloud credentials can access a managed Kubernetes cluster. Returns the IAM access verdict and, for EKS, the network-reachability verdict (so a private or IP-restricted control plane surfaces the IP to allowlist).

```json title="Response"
{
  "data": {
    "accessible": true,
    "principal": "arn:aws:iam::123456789012:role/zopnight-cluster-reader",
    "network": {
      "reachable": false,
      "reason": "ip_not_allowlisted",
      "publicAccess": true,
      "ourIp": "34.29.167.157/32"
    }
  }
}
```

## Last Synced At

### GET /resources/last-synced

Returns the most recent successful discovery timestamp per provider/cloud account. Used by the sync status banner.

```json title="Response"
{
  "data": [
    {
      "cloudAccountID": "ca_abc123",
      "provider": "aws",
      "lastSyncedAt": "2026-04-29T05:00:00Z"
    }
  ]
}
```

## Get Filter Fields

### GET /resources/filter-fields

Get available filter options (distinct types, providers, regions, statuses) for building filter UIs.

```json title="Response"
{
  "data": {
    "types": [
      "aws-ec2", "aws-rds", "aws-eks", "aws-eks-nodegroup",
      "aws-eks-deployment", "aws-eks-statefulset", "aws-eks-cronjob",
      "gcp-compute", "gcp-cloud-sql", "gcp-gke", "gcp-gke-nodepool",
      "gcp-gke-deployment", "gcp-gke-statefulset", "gcp-gke-cronjob",
      "azure-vm", "azure-aks", "azure-aks-agentpool",
      "azure-databricks", "azure-databricks-cluster",
      "azure-databricks-instance-pool", "azure-databricks-warehouse"
    ],
    "providers": ["aws", "gcp", "azure"],
    "regions": ["us-east-1", "us-west-2", "europe-west1"],
    "statuses": ["running", "stopped"]
  }
}
```

## Refresh Discovery

Trigger an on-demand resource discovery scan for a specific cloud account. Discovery runs across all enabled regions and updates the resource inventory.

### POST /resources/refresh

Trigger a resource discovery refresh.

```bash title="Request"
curl -X POST https://zopnight.com/api/resources/refresh \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "cloudAccountID": "ca_abc123",
    "cloudAccountName": "Production AWS",
    "provider": "aws"
  }'
```

```json title="Response"
{
  "data": {
    "refreshID": "ref_xyz789",
    "status": "queued"
  }
}
```

## Refresh Status

### GET /resources/refresh/status

Check the status of a discovery refresh.

```json title="Response"
{
  "data": {
    "id": "ref_xyz789",
    "status": "success",
    "discovered": 47,
    "startedAt": "2025-01-20T08:00:00Z",
    "completedAt": "2025-01-20T08:02:15Z"
  }
}
```

## Resource Object

| Field | Type | Description |
|---|---|---|
| `id` | string | Unique resource ID |
| `name` | string | Resource display name |
| `uid` | string | Cloud provider native resource identifier |
| `type` | string | Resource type (e.g., aws-ec2, gcp-compute, azure-vm) |
| `instanceType` | string | Instance size/type (e.g., t3.medium) |
| `sizeGB` | number? | Storage size in GB (storage resources) |
| `unitCount` | integer? | Container/unit count (containerized resources) |
| `region` | string | Cloud region |
| `status` | string | Current status (running, stopped, etc.) |
| `cloudAccountID` | string | Connected cloud account ID |
| `cloudAccountName` | string | Cloud account display name |
| `provider` | string | Cloud provider (aws, gcp, azure) |
| `parentUID` | string | Parent resource UID (e.g., cluster for a node) |
| `childCount` | integer | Number of child resources |
| `schedulable` | boolean | Whether the resource supports start/stop scheduling |
| `tags` | object | Cloud provider tags as key-value pairs |
| `createdAt` | string | ISO 8601 creation timestamp |
| `updatedAt` | string | ISO 8601 last update timestamp |

See [Cloud Support Matrix](https://zop.dev/docs/cloud-setup/cloud-support) for the full list of supported resource types per cloud provider.
