Apps, stacks, resources, and providers
Every Netherframe project is built from a small, regular hierarchy of Python constructs:
an App contains Stacks, and each Stack contains Providers,
Resources, DataSources, EphemeralResources, and Outputs.
flowchart TD
A["App (platform)"] --> B["Stack (network)"]
A --> C["Stack (storage)"]
B --> D["Provider (aws)"]
B --> E["Resource (aws_vpc.main)"]
B --> F["Resource (aws_subnet.public)"]
C --> G["Provider (aws)"]
C --> H["Resource (aws_s3_bucket.assets)"]
C --> I["Output (bucket_id)"]
App
An App is the root of an infrastructure deployment. It owns:
- The app-wide dependency graph across all its stacks
- Execution settings (
recovery_strategy, concurrency limits, deferred approval policy) - App-wide checks and finalizers (
app.check(...)) - The hybrid state backend (explicit in Python, or selected via
backend_*settings)
Register an app in [tool.nf].apps in pyproject.toml as module:object (for example,
apps = ["infra:app"]). The target may be an App instance or—recommended for real
projects—a factory function whose type-annotated parameters become typed CLI inputs
(nf plan --app web ++env=prod).
Stack
A Stack groups related resources under a domain name such as network, storage,
or identity.
Every managed resource gets a state address of the form:
<stack_id>.<resource_type>.<resource_id>
For example, storage.aws_s3_bucket.assets. Data sources use
<stack_id>.data.<type>.<id>, ephemeral resources <stack_id>.ephemeral.<type>.<id>, and
outputs <stack_id>.output.<id>.
In hybrid execution:
- Stacks are organizational scopes, not execution barriers. A whole-app plan walks every stack's constructs in one graph, applying independent stacks in parallel.
- Whole-app saved plans cover every stack. If you need independently reviewed plans or
separate state lifecycles, define separate
Apps with separate state backends. - Removing a stack from an app plans its deletion. Just as Terraform deletes a removed module, a whole-app plan deletes resources belonging to stacks the app no longer declares (requiring review or a saved plan).
Provider
A Provider configures how resources in its scope authenticate and talk to a service
or cloud (region, account, endpoint, alias, default tags).
Providers are normally instantiated inside a stack and bound to resources in one of four ways:
- Implicitly as the stack's default provider for that type
- Inside a
with provider:context block - Explicitly via
nf_provider=provideron a resource - Through provider-bound factories (for example,
aws.Vpc(...))
Because provider choice determines which account and region resources target, keeping provider setup visible inside each stack makes reviews safer.
Resource, DataSource, EphemeralResource, and Output
Resourcedeclares a managed infrastructure object. Use generated typed classes (S3Bucket(...)) for editor completion and schema-typed nested blocks, or genericResource(nf_type="aws_s3_bucket", ...)when exploring an ungenerated provider.DataSourcereads an existing object without managing its lifecycle.EphemeralResourceopens a short-lived secret or lease during a run; its values may flow only to write-only arguments or other ephemeral resources, never to plans or state.Outputexposes a value from a stack after apply (marking secrets as sensitive).
Scoping and stable IDs (nf_autoid)
Constructs need a parent scope (nf_scope) and a stable identifier (nf_id):
# coding: nf_autoid
from nf.core import App, Bind, BindContext, Stack
from nf.providers.hashicorp.aws import AwsProvider, S3Bucket
with App() as platform, Stack() as storage, BindContext:
aws: Bind[AwsProvider] = AwsProvider(region="us-east-1")
assets: Bind[S3Bucket] = S3Bucket(
bucket="replace-with-a-globally-unique-name",
nf_provider=aws,
)
In a file starting with # coding: nf_autoid:
- Entering
with App() as platform, Stack() as storage, BindContext:sets the active scope and injectsnf_id="platform"andnf_id="storage". assets: Bind[S3Bucket] = ...injectsnf_id="assets", producing the state addressstorage.aws_s3_bucket.assets.- Plain assignments without
Bindare never rewritten, so refactoring temporary Python variables never accidentally renames managed resources.
Keep IDs stable after apply. Changing a stack ID or resource ID changes its state address, which plans a delete-and-create unless you move state explicitly with
nf state mv.