<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
# Cloud Resource Drift Detection — API Reference

## Terraform CLI

```bash
# Plan with detailed exit code (0=no changes, 2=drift)
terraform plan -detailed-exitcode

# Refresh-only plan (detect drift without applying)
terraform plan -refresh-only -detailed-exitcode

# JSON output for parsing
terraform plan -json -refresh-only

# Show state
terraform state list
terraform state show RESOURCE_ADDRESS

# Import unmanaged resource
terraform import RESOURCE_ADDRESS RESOURCE_ID
```

## CloudFormation Drift

```bash
# Detect drift
aws cloudformation detect-stack-drift --stack-name STACK

# Check status
aws cloudformation describe-stack-drift-detection-status \
  --stack-drift-detection-id ID

# Get drifted resources
aws cloudformation describe-stack-resource-drifts \
  --stack-name STACK \
  --stack-resource-drift-status-filters MODIFIED DELETED

# List drifted stacks
aws cloudformation list-stacks --output json | \
  jq '.StackSummaries[] | select(.DriftInformation.StackDriftStatus == "DRIFTED")'
```

## AWS Config

```bash
# Compliance summary
aws configservice describe-compliance-by-config-rule

# Non-compliant resources
aws configservice get-compliance-details-by-config-rule \
  --config-rule-name RULE --compliance-types NON_COMPLIANT

# Resource config history
aws configservice get-resource-config-history \
  --resource-type TYPE --resource-id ID

# Aggregated compliance
aws configservice describe-aggregate-compliance-by-config-rules \
  --configuration-aggregator-name AGGREGATOR
```

## ArgoCD Drift

```bash
# Application diff
argocd app diff APP_NAME

# Sync status
argocd app get APP_NAME -o json | jq '.status.sync.status'

# List out-of-sync apps
argocd app list -o json | jq '.[] | select(.status.sync.status != "Synced")'
```

## Key Exit Codes

| Tool | Code | Meaning |
|------|------|---------|
| `terraform plan -detailed-exitcode` | 0 | No changes |
| `terraform plan -detailed-exitcode` | 1 | Error |
| `terraform plan -detailed-exitcode` | 2 | Drift detected |
