Skip to content

Coming from Terraform, OpenTofu, or Terragrunt

Netherframe runs the exact same Terraform provider binaries (tfplugin5/tfplugin6 over gRPC) and speaks the same resource schemas, state concepts, and registry/mirror protocols. The difference is that you author infrastructure in typed Python 3.15+ and get safety guarantees around the run itself—without installing the terraform or tofu CLI.


Side-by-side: HCL vs. Netherframe Python

variable "env" {
  type    = string
  default = "dev"
}

variable "subnet_cidrs" {
  type    = list(string)
  default = ["10.42.1.0/24", "10.42.2.0/24"]
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_vpc" "main" {
  cidr_block           = "10.42.0.0/16"
  enable_dns_support   = true
  enable_dns_hostnames = true
  tags                 = { Env = var.env }
}

resource "aws_subnet" "app" {
  for_each   = { for idx, cidr in var.subnet_cidrs : idx => cidr }
  vpc_id     = aws_vpc.main.id
  cidr_block = each.value
  tags       = { Name = "app-${var.env}-${each.key}" }
}

output "vpc_id" {
  value = aws_vpc.main.id
}
# coding: nf_autoid

from typing import Literal

from nf.core import App, Bind, BindContext, Output, Stack
from nf.providers.hashicorp.aws import AwsProvider, Subnet, Vpc


def network(
    env: Literal["dev", "prod"] = "dev",
    subnet_cidrs: tuple[str, ...] = ("10.42.1.0/24", "10.42.2.0/24"),
) -> App:
    with App(nf_id="network") as app, Stack(nf_id=f"net-{env}"), BindContext:
        aws: Bind = AwsProvider(region="us-east-1")
        main: Bind = Vpc(
            nf_provider=aws,
            cidr_block="10.42.0.0/16",
            enable_dns_support=True,
            enable_dns_hostnames=True,
            tags={"Env": env},
        )
        for idx, cidr in enumerate(subnet_cidrs):
            Subnet(
                nf_id=f"app-{idx}",
                nf_provider=aws,
                vpc_id=main.output.id,
                cidr_block=cidr,
                tags={"Name": f"app-{env}-{idx}"},
            )
        vpc_id: Bind = Output(value=main.output.id)
    return app

Register apps = ["app:network"] in pyproject.toml, then run:

nf plan --app network ++env=prod --diff --out prod.plan.json
nf apply --app network --plan-file prod.plan.json

Command and concept rosetta stone

Terraform / OpenTofu / Terragrunt Netherframe equivalent Notes
terraform init nf generate providers ... (bindings) + automatic binary fetch Provider binaries download and verify automatically (SHA256SUMS + OpenPGP) into ~/.nf/providers; supports network & filesystem mirrors.
terraform plan -out=tfplan nf plan --app <app> --out plan.json Saved plan embeds SHA-256 content_digest, state serial/lineage, provider fingerprints, inputs, and declared app checks.
terraform plan -detailed-exitcode nf plan --app <app> --expect-no-changes Exits 0 (no changes), 3 (changes/drift), 1 (error), 2 (CLI usage).
terraform apply tfplan nf apply --app <app> --plan-file plan.json Refuses stale state, mismatched inputs, or removed checks.
terraform destroy nf destroy --app <app> Automatically reuses the deployment inputs recorded by the last apply; refuses conflicting overrides.
terraform state mv / rm / taint / force-unlock nf state mv / rm / taint / untaint / force-unlock Works across every hybrid state backend (local, S3, GCS, Azure, Consul, PostgreSQL, HCP Terraform).
variable + -var / .tfvars / TF_VAR_* App factory parameters + ++name=value / ++@file.toml No TF_VAR_* / NF_* env vars. Secret[T] is refused on argv (use ++@<(...)). Inspect with nf vars.
count / for_each Normal Python for / if Hybrid rejects count/for_each meta-arguments; instantiate one construct per item in Python.
Multiple provider aliases / Terragrunt for region in regions: AwsProvider(...) + Python modules Providers are ordinary Python objects—loop over regions/accounts freely (see examples/aws_multi_region).
import { ... } block .import_from(...), LifecycleRules(adopt=...), or --adopt-from Also supports runtime import_from(parent.output.id) resolved in the same apply.
removed { destroy = false } LifecycleRules(retain="why") + Teardown[bool] Keeps the resource managed in state, protects dependencies, and runs @retained_check after destroy.
check blocks (warn-only) / OPA / Sentinel @app.check(phase="prerequisites\|plan\|apply\|finalize") + @post_apply_check + nf lint Hard-fail gates in plain Python, re-checked under the state lock, plus crash-resumable finalizers (nf state verify).
Partial apply left behind recovery_strategy="ROLLBACK" (or default CHECKPOINT) Deletes newly created resources across any provider if a later step fails.
One lock per state file PostgreSQLGraphBackend + --concurrent-applies Row-level state with fenced operations and concurrent applies for provably disjoint changes.
Terragrunt run-all / wrapper scripts nf.sdk.Project / AsyncProject First-party Python API for every nf command returning typed dataclasses.

Things that intentionally work differently

  • Fail-closed Terraform-only features: Hybrid execution explicitly rejects provisioner / connection blocks (use cloud-init/user-data or baked images), create_before_destroy, count/for_each, Move/Import constructs, and Fn.* functions (use Python or @hybrid_runtime). See Hybrid Execution Semantics.
  • No silent environment overrides: Netherframe reads no NF_* variables so an old shell export cannot retarget prod.
  • Stacks inside one app share one graph: Unlike separate Terraform root modules, all stacks in a Netherframe App plan and apply together in one dependency graph. Use separate Apps for separate state lifecycles.
  • Need to keep Terraform/OpenTofu running during a transition? Register apps under [tool.nf].terraform_apps and run nf synth to export Terraform JSON under .nf.out/.

How to migrate an existing Terraform project

You can migrate incrementally without recreating live infrastructure:

  1. Convert HCL to typed Python + an adoption manifest:
    nf convert ./terraform-module ./converted
    
    This writes typed Python modules and a *.adopt.json manifest mapping every Terraform state address (including count/for_each instances and module renames) to its new Netherframe address.
  2. Plan against your existing terraform.tfstate:
    nf plan --app network --adopt-from converted/network.adopt.json \
      --terraform-state ./terraform-module/terraform.tfstate --diff --out migrate.plan.json
    
  3. Review and apply: Confirm every existing object is listed as an import (with no unexpected replacements), then run nf apply --app network --plan-file migrate.plan.json.

Next steps