Skip to content

nf drift

Detect and optionally fix drift between Netherframe code and actual infrastructure state.

Synopsis

nf drift [COMMAND] [OPTIONS] [PATHS...]

Commands

  • detect: inspect drift and print details
  • fix: generate or apply source patches for detected drift
  • check: exit-code-oriented drift check for CI

If no paths are provided, drift commands scan the current directory for Python files.

Detection Modes

Live Provider Mode

This is the default mode. It compares code against live provider reads. Each resource in code is read in one of two ways:

  • Refreshed from state. If the resource is in the project's state (matched by resource type and nf_id, or the variable name when nf_id is implicit), the provider reads it from its stored state, as terraform plan does. This works for every resource Netherframe manages, including ones identified by values the provider assigns, such as a VPC's vpc_id.
  • Imported by identity. A resource that isn't in state is imported by the resource identity its provider publishes (the attributes that identify it), filled from its code; this works only when those arguments are set there (for example bucket for aws_s3_bucket). When they aren't, the failure says which are missing and whether the provider assigns them, e.g. aws_sqs_queue is identified by url; the provider assigns url, so it can't come from code. For providers without identity schemas, import-ID resolver plugins (nf.drift.import_id_resolvers entry points) are used instead.

By default the state is a hybrid app's: in the backend the settings choose (backend_type and its options, see nf backend), else the local .nf.out/nf.tfstate. Use --state FILE to name a state file, or --no-state to import everything. If the same nf_id and type appear in more than one stack, drift detection reports it instead of guessing.

Legacy State File Mode

Use --legacy to compare against a state file instead of live providers.

Use it when:

  • you are working from exported or older Terraform state
  • live provider access is not available
  • you want a more migration-oriented comparison step

Common Options

  • --filter, -f TEXT: filter by resource type; repeatable
  • --legacy, -l: use legacy state-file mode instead of live providers
  • --state-file PATH: legacy state file path; default legacy.tfstate
  • --state FILE: Netherframe state to refresh resources from (live provider mode); default: the configured backend, then .nf.out/nf.tfstate
  • --no-state: import every resource instead of refreshing from state
  • --strict/--no-strict: fail if resources cannot be read
  • --allow-id-guessing: allow fallback import-ID guessing
  • --provider TEXT: provider source or short name; repeatable
  • --provider-config PATH: JSON file with provider configuration and optional source overrides

Which Provider Reads A Resource

Without --provider, drift detection starts the providers the code's resources come from. A resource of a generated provider class uses that class's package (keycloak/keycloak, and hashicorp/google-beta for google-beta's google_* types). A resource declared without one (Resource(type=...)) uses the provider state recorded for it, and otherwise Terraform's implied provider, the type's first word. A bare --provider name is the source the config file's sources gives it; that name, like an implied one, is otherwise the source its installed generated provider package declares, else hashicorp/<name>. When installed packages declare the name with different sources, drift detection reports it and asks for the source address (--provider integrations/github) instead of guessing.

Provider Config File Shape

{
  "providers": {
    "aws": {
      "region": "us-east-1"
    }
  },
  "sources": {
    "aws": "hashicorp/aws"
  }
}

nf drift detect

nf drift detect [PATHS...] [OPTIONS]

Use detect when you want a human-readable report of added, removed, or modified resources.

Examples:

nf drift detect
nf drift detect src/
nf drift detect -f aws_s3_bucket
nf drift detect --provider hashicorp/aws --provider-config providers.json
nf drift detect --state .nf.out/nf.tfstate
nf drift detect --legacy --state-file legacy.tfstate

nf drift fix

nf drift fix [PATHS...] [OPTIONS]

Additional options:

  • --dry-run: preview the patches without applying
  • --auto-approve: skip the confirmation prompt

Examples:

nf drift fix --dry-run --provider hashicorp/aws --provider-config providers.json
nf drift fix --auto-approve --provider hashicorp/aws --provider-config providers.json

nf drift check

nf drift check [PATHS...] [OPTIONS]

This is the CI-friendly variant.

Exit codes:

  • 0: no drift detected
  • 1: runtime or drift-check error
  • 2: CLI usage error
  • 3: drift detected

Example:

nf drift check --provider hashicorp/aws --provider-config providers.json

Practical Advice

  • start with detect before using fix
  • scope the path set narrowly in large repositories
  • prefer explicit provider configuration in CI
  • use legacy mode when you are comparing against saved state rather than live infrastructure