Skip to content

Convert a Terraform project to Netherframe

Convert one Terraform module into a Python stack, review the translation and use its adoption manifest to plan against the objects in your existing Terraform state.

Before you start: install Netherframe, keep a copy of the module's source and export its state. You need credentials for provider reads during planning. Source conversion itself does not need cloud credentials or a Terraform executable. Run nf from the new app's project directory with its Python environment active.

Optional: rehearse locally first

You can exercise the whole migration with Random before touching a cloud estate. Generate and install its bindings, then create terraform-project/main.tf:

terraform {
  required_providers {
    random = { source = "hashicorp/random", version = "3.9.1" }
  }
}
provider "random" {}
resource "random_pet" "example" { length = 2 }
terraform -chdir=terraform-project init
terraform -chdir=terraform-project apply

Approve the local random-name creation, then follow the steps below. This rehearsal needs the Terraform executable but no cloud account. For an existing project, use your actual module and state instead.

1. Select a module and export its state

Use a narrow root module first. In this walkthrough its source is in terraform-project/, next to the new nf app. If it uses a remote backend, export state from its initialized Terraform working directory:

terraform -chdir=terraform-project state pull > terraform-state.json

A local state file can be copied instead. Keep the source state and new nf state separate. The export is a point-in-time snapshot; coordinate the cutover so another Terraform run does not change those objects between review and adoption.

2. Convert the source

From the new app's project directory:

nf convert ./terraform-project --output . --package imported --report conversion-report.txt

Expected files:

app.py                  # you create this in the next step
imported/
  __init__.py
  main.py
  modules/              # when the source calls local modules
imported.adopt.json
conversion-report.txt
terraform-state.json

Read the report and every TODO(nf convert) marker before running the generated app. Installed provider bindings produce typed constructors; other types use generic constructs. Generate the bindings before conversion if you want the typed surface.

For public registry modules, GitHub sources or HTTP(S) archives, add --fetch-modules. Pin their versions/revisions first. Private registries and arbitrary Git transports are not fetched by this option. See the converter reference.

3. Wire the generated stack into an app

Create app.py:

from nf.core import App
from imported import ImportedStack

app = App(nf_id="migration")
stack = ImportedStack(nf_scope=app, nf_id="imported")
app.enable_hybrid_execution_local(path=".nf.out/adopted.tfstate")

Pass any required variables as keyword arguments to ImportedStack; its generated constructor is the source of truth for their names and types. Keep nf_id="imported" so the stack ID matches the manifest generated for package imported.

Add this to the existing pyproject.toml:

[tool.nf]
apps = ["app:app"]

Check that the generated stack declares the provider configurations its resources need. Terraform permits an implicit default provider; direct nf execution needs an explicit one. If the source omitted it, add the corresponding provider to stack. For example, for a Random module with no converted provider block:

from nf.core import App, Stack
from nf.providers.hashicorp.random import RandomProvider

app = App(nf_id="migration")
stack = Stack(nf_scope=app, nf_id="imported")  # the converted stack of app.py

RandomProvider(nf_scope=stack, nf_id="random")

The rehearsal's explicit provider "random" {} already converts to that configuration, so no additional provider is needed there. Preserve aliases and source/version pins when adding provider configurations for a real project.

The example chooses a separate local nf backend to make the state transition visible. Select your production backend before a real cutover; see backends and state.

4. Plan adoption and save it for review

nf plan --app app \
  --adopt-from imported.adopt.json \
  --terraform-state terraform-state.json \
  --adopt-missing error \
  --out reviewed-adoption.json

The plan should show imports for the existing objects you intend to transfer. It can also show updates when the converted configuration differs from the provider's current view. Review replacements, deletes and unexpected creates before proceeding.

--adopt-missing error makes a missing adoption target fail instead of becoming a create. Planning reads providers but does not write the adopted objects into nf state.

5. Apply the reviewed plan and verify

nf apply --app app --plan-file reviewed-adoption.json
nf plan --app app

Review and approve the imports. For unattended applies, import approval is a separate opt-in (--approve-imports); ordinary auto-approval does not approve adoption by itself.

After adoption, a fresh plan should show no unexpected changes. Matching existing objects need no mutation: adoption records their state. Complete the cutover by making nf the writer for this resource group, then expand to another module when the first group is stable.

Next: reusable stacks, state operations, or CI/CD.

Understand the migration

Conversion, adoption and backend migration are separate

Conversion changes source representation: variables become Python constructor arguments, locals become Python expressions, and local modules become helper classes. It also records address changes in the manifest. It does not alter your Terraform backend or live objects.

Adoption tells the new app which existing objects correspond to its declarations. With terraform_address entries, nf reads the exported object's attributes, provider-private data and identity, upgrades its state if necessary and refreshes it through the provider. It does not require that resource to implement an import RPC.

Moving the resulting nf state to another backend is a further operation. Keep that change separate until the converted app and ownership mapping have been verified.

Address mapping preserves the connection to existing objects

A Terraform resource in module.edge may become edge_main in the generated stack. count and for_each instances also get explicit generated names. The adoption manifest maps these names back to Terraform state addresses; review it alongside the Python changes.

If you choose another stack ID, use the manifest's stack_map rather than manually editing every address. See adoption manifests.

Resolve translation gaps before applying

The report identifies expressions, provisioners, modules and other constructs that could not be translated. Retained HCL and a successful Python import do not prove that the direct engine can execute every feature. Read conversion coverage and hybrid semantics, then resolve the marked parts and replan.