Skip to content

Drifts

Query, analyze, and remediate infrastructure drifts detected by scans.

Base path: /api/drifts

Authentication: Bearer token required on all routes

List All Drifts

GET /api/drifts/

Scope: drifts:read

List all drifts across all repositories for the authenticated user.

Query Parameters

ParameterTypeRequiredDescription
pagenumberNoPage number (default: 1)
limitnumberNoItems per page (default: 20)
statusstringNoFilter by status (detected, acknowledged, resolved, ignored)
severitystringNoFilter by severity (critical, high, medium, low)

Response

json
{
  "success": true,
  "data": [
    {
      "_id": "drift1",
      "resourceType": "aws_security_group",
      "resourceAddress": "module.vpc.aws_security_group.main",
      "severity": "high",
      "status": "detected",
      "changeType": "changed",
      "scan": "scan123",
      "repositoryConfig": "abc123",
      "detectedAt": "2025-06-15T10:32:00.000Z"
    }
  ]
}

Example

bash
curl -H "Authorization: Bearer TOKEN" \
  "https://api.controlinfra.com/api/drifts/?status=detected&severity=high"

Advanced Query

GET /api/drifts/query

Scope: drifts:read

Advanced drift search with filters, facets, and full-text search.

Query Parameters

ParameterTypeRequiredDescription
qstringNoFree-text search query
statusstringNoDrift status filter
severitystringNoSeverity filter
resourceTypestringNoTerraform resource type filter
repositoryConfigIdstringNoRepository config filter
pagenumberNoPage number
limitnumberNoItems per page
sortstringNoSort field (e.g., -detectedAt)

Example

bash
curl -H "Authorization: Bearer TOKEN" \
  "https://api.controlinfra.com/api/drifts/query?q=security_group&severity=high&sort=-detectedAt"

Get Aggregations

GET /api/drifts/aggregations

Scope: drifts:read

Get drift aggregations for dashboard charts (by severity, resource type, trend over time).

Response

json
{
  "success": true,
  "data": {
    "bySeverity": {
      "critical": 2,
      "high": 15,
      "medium": 45,
      "low": 12
    },
    "byResourceType": {
      "aws_security_group": 8,
      "aws_iam_role": 5
    },
    "trend": [...]
  }
}

Export CSV

GET /api/drifts/export

Scope: drifts:read

Export drifts as a CSV file.

Query Parameters

Same filters as Advanced Query.

Response

Returns text/csv content with drift data.

Example

bash
curl -H "Authorization: Bearer TOKEN" \
  "https://api.controlinfra.com/api/drifts/export?status=detected" \
  -o drifts.csv

Get Query Suggestions

GET /api/drifts/suggestions

Scope: drifts:read

Get autocomplete suggestions for the drift search query input.

Get Field Autocomplete

GET /api/drifts/autocomplete

Scope: drifts:read

Get field-specific autocomplete values from actual drift data.

Query Parameters

ParameterTypeRequiredDescription
fieldstringYesField name to autocomplete
prefixstringNoPrefix to filter by

List Drifts by Scan

GET /api/drifts/scan/:scanId

Scope: drifts:read

List all drifts detected in a specific scan.

Path Parameters

ParameterTypeDescription
scanIdstringScan ID

List Drifts by Repository

GET /api/drifts/repository/:repositoryConfigId

Scope: drifts:read

List drifts for a specific repository configuration.

Path Parameters

ParameterTypeDescription
repositoryConfigIdstringRepository config ID

Get Drift Statistics

GET /api/drifts/repository/:repositoryConfigId/statistics

Scope: drifts:read

Get drift statistics for a repository (counts by severity, resolution rates, etc.).

Path Parameters

ParameterTypeDescription
repositoryConfigIdstringRepository config ID

Get Drift

GET /api/drifts/:driftId

Scope: drifts:read

Get full details for a specific drift including the diff and AI analysis.

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Response

json
{
  "success": true,
  "data": {
    "_id": "drift1",
    "resourceType": "aws_security_group",
    "resourceAddress": "module.vpc.aws_security_group.main",
    "severity": "high",
    "status": "detected",
    "diff": "...",
    "aiAnalysis": {
      "summary": "Security group ingress rule was modified...",
      "riskLevel": "high",
      "recommendation": "Review and revert unauthorized changes"
    }
  }
}

Re-Analyze Drift

POST /api/drifts/:driftId/reanalyze

Scope: drifts:write

Re-run AI analysis on a drift.

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Update Drift Status

PATCH /api/drifts/:driftId/status

Scope: drifts:write

Update the status of a drift (e.g., acknowledge, resolve, ignore).

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Request Body

FieldTypeRequiredDescription
statusstringYesNew status (acknowledged, resolved, ignored)

Example

bash
curl -X PATCH https://api.controlinfra.com/api/drifts/drift1/status \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "acknowledged"}'

Generate Fix

POST /api/drifts/:driftId/generate-fix

Scope: drifts:write

Generate AI-powered Terraform code to fix a drift.

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Response

json
{
  "success": true,
  "data": {
    "fixCode": "resource \"aws_security_group\" \"main\" {\n  ...\n}",
    "explanation": "This fix reverts the security group to its declared state..."
  }
}

Create Pull Request

POST /api/drifts/:driftId/create-pr

Scope: drifts:write

Create a GitHub pull request with the generated fix code.

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Response

json
{
  "success": true,
  "data": {
    "prUrl": "https://github.com/org/repo/pull/42",
    "prNumber": 42,
    "branch": "controlinfra/fix-drift-abc123"
  }
}

Approve Fix

POST /api/drifts/:driftId/approve-fix

Scope: drifts:write

Approve a generated fix in the approval workflow.

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Submit Feedback

POST /api/drifts/:driftId/feedback

Scope: drifts:write

Submit feedback on the AI analysis quality for a drift.

Path Parameters

ParameterTypeDescription
driftIdstringDrift ID

Request Body

FieldTypeRequiredDescription
ratingnumberYesRating (1-5)
commentstringNoOptional feedback comment