Skip to content

Generate and use a provider package

Generate typed Python bindings for the Random provider, install them as a project dependency, and plan a resource with hybrid execution. Use the same steps for other Terraform providers by changing the source address and version.

Before you start: install Netherframe in a Python 3.15+ uv project. The first generation needs access to the provider registry or a cached schema and provider binary. This example needs no cloud account. For source-checkout or pip setup, see creating a project and installing bindings in Tutorial 1. Run the commands from your project directory with its Python environment active.

1. Choose an exact provider release

This tutorial uses hashicorp/random version 3.9.1. If you are choosing a different provider, use its source address (namespace/name) and a release you intend to use.

nf generate providers hashicorp/random --version 3.9.1 --yes

The package is written under providers/hashicorp/random/:

providers/hashicorp/random/
  pyproject.toml
  README.md
  netherframe/providers/hashicorp/random/
  nf/providers/hashicorp/random/

2. Install it in the app's environment

uv add --editable ./providers/hashicorp/random

This records the generated package as a local dependency. uv sync can restore it on another machine if the generated directory is available.

The distribution is named netherframe.providers.hashicorp.random. Its short Python import path is nf.providers.hashicorp.random; the distribution name and import path are intentionally different.

3. Use the bindings

Create app.py:

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

app = App(nf_id="binding-demo")
stack = Stack(nf_scope=app, nf_id="names")
provider = RandomProvider(nf_scope=stack, nf_id="random")
pet = Pet(nf_scope=stack, nf_id="example", nf_provider=provider, length=2)
Output(nf_scope=stack, nf_id="pet_name", value=pet.ref_id_)

app.enable_hybrid_execution_local(path=".nf.out/hybrid.tfstate")

Add the app to your existing pyproject.toml:

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

4. Verify the result

nf plan --app app --out reviewed-plan.json

The plan should show a create for names.random_pet.example and the pet_name output. The provider generates the name at apply time.

To apply the saved plan and verify convergence, follow Tutorial 1: Apply the saved plan. For an AWS example, generate hashicorp/aws bindings and follow the AWS quickstart.

Understand the generated package

Bindings describe the schema; the binary implements it

The package contains Python constructors, typed configuration, references and the provider source/version pin. The provider executable implements schema validation and resource operations. Installing bindings does not install a cloud CLI, and constructing a resource does not contact its cloud service.

Generation normally obtains the schema through the provider's native protocol. A captured schema can also be used by the Python generation API. The CLI's --schema-loading option controls the Terraform CLI schema-capture fallback; it does not choose which execution engine will later run your app.

Versions and binding revisions

Provider 3.9.1 initially produces Python distribution version 3.9.1. A binding fix for the same provider can use --binding-revision 1, producing 3.9.1.1 while keeping the binary pin at 3.9.1. Regenerating never increments the revision automatically.

[tool.nf] and the installed _generation.json record the generator version, core floor and schema fingerprint. See provider releases for building reviewable wheels, compatibility rules and publishing.

Names, references and nested configuration

Generated classes remove the provider prefix from the Terraform type. For example, random_pet becomes Pet, while aws_s3_bucket becomes S3Bucket.

Terraform entry Generated naming pattern Terraform output
Resource Instance resource
Data source InstanceDataSource data
Ephemeral resource PasswordEphemeralResource ephemeral
List resource InstanceListResource nf.tfquery.json for terraform query
Action A name ending in Action action
State store A name ending in StateStore The stack's terraform block

These names are patterns, not a claim that every provider implements every kind. Generated nested block classes describe structured configuration. Reserved Python names are adjusted (type becomes type_); generated references such as pet.ref_id_ refer to computed attributes. Your editor and the generated README help identify the available surface. See providers and runtime values.

Use nf_provider=provider to select a particular configuration. Generated classes also record their provider's local name, so providers whose type prefix differs from their source name can select the correct default configuration.

Terraform features and direct execution

Bindings can represent more Terraform features than the direct engine executes. List resources belong to Terraform queries; state stores and actions have separate execution requirements. Lifecycle metadata includes features that direct execution explicitly refuses when unsupported. Check hybrid semantics before using those features in a direct app.

Generate a repeatable set

Once one provider works, keep the team's provider inputs in a config file:

providers:
  - name: hashicorp/random
    version: "3.9.1"
  - name: hashicorp/aws
    version: "6.73.0"
nf generate providers --config nf-providers.yaml --parallel --yes

Use --clean for a fresh generation and review the output when upgrading a provider or generator. Package generation runs in a temporary directory on the destination filesystem; the current package remains in place until generation and its formatting step complete. Failures discard the candidate, preserving the existing pyproject.toml and bindings. Replacement uses a backup and renames, with restoration if installing the candidate fails. If restoration itself fails, the error reports the retained backup path for recovery. This is not a crash-atomic directory exchange. Code-only (--no-package) and incremental runs retain their existing behavior.

If generated directories are excluded from version control, retain this config and regenerate them before installing or syncing a project that depends on those paths.

For every flag, see nf generate providers. For discovering provider sets, see nf providers.