Data Sources, Ephemeral Resources, and Outputs Reference
Alongside managed Resource constructs, Netherframe provides three non-managed construct
types: DataSource (read-only queries), EphemeralResource (short-lived values
never stored in state), and Output (exported stack values).
DataSource
A DataSource reads existing external information through a provider's ReadDataSource
RPC without creating, updating, or deleting any infrastructure.
- State address:
<stack>.data.<type>.<id>(for example,network.data.aws_ami.ubuntu). A data source and a managed resource may share the same type andnf_idwithout colliding. - When it is read:
- At plan time when all its configuration arguments are known and no construct in its
depends_onlist has a planned change. The read result is stored inside saved plans sonf apply --plan-fileuses the exact values reviewed. - At apply time (deferred read, listed in
deferred_reads) when its configuration depends on a value known only after apply or a resource independs_onis changing. - State storage: Cached in state with
mode: "data"until removed from the app or the stack is destroyed.
Example (generic and typed)
# coding: nf_autoid
from nf.core import App, Bind, BindContext, DataSource, Output, Stack
from nf.providers.hashicorp.aws import AwsProvider
from nf.providers.hashicorp.aws.data_sources.caller_identity_data_source import CallerIdentityDataSource
with App(nf_id="lookup-demo") as app, Stack() as info, BindContext:
aws: Bind = AwsProvider(region="us-east-1")
# Generated typed data source
current: Bind = CallerIdentityDataSource(nf_provider=aws)
# Generic data source (works for any provider without generated bindings)
ami: Bind = DataSource(
nf_type="aws_ami",
nf_provider=aws,
most_recent=True,
owners=["amazon"],
filter=[{"name": "name", "values": ["al2023-ami-*"]}],
)
account_id: Bind = Output(value=current.output.account_id)
ami_id: Bind = Output(value=ami.output.id)
EphemeralResource
An EphemeralResource opens a short-lived secret, token, or lease via
OpenEphemeralResource, renews it if the provider requests renewal (RenewEphemeralResource),
and closes it cleanly (CloseEphemeralResource) when the run ends.
- State address:
<stack>.ephemeral.<type>.<id>. - Zero persistence guarantee: Ephemeral values may flow only into provider
write_onlyarguments (such asvalue_wo) or otherEphemeralResourceconstructs. Passing an ephemeral value into a normal resource argument,Output, or state is refused. - When it is opened: Opened in dependency order during
planif its inputs are known; otherwise deferred and opened duringapplyonce prerequisites finish.
Example
# coding: nf_autoid
from nf.core import App, Bind, BindContext, Provider, Resource, Stack
from nf.core.constructs.resources import EphemeralResource
with App(nf_id="ephemeral-demo") as app, Stack() as secrets, BindContext:
aws: Bind = Provider(nf_type="aws", region="us-east-1")
# Opened for the duration of the run, closed on exit, never written to state or plans
temp_secret: Bind = EphemeralResource(
nf_type="aws_secretsmanager_random_password",
nf_provider=aws,
password_length=32,
)
# Flows strictly into a write-only argument paired with a version trigger
param: Bind = Resource(
nf_type="aws_ssm_parameter",
nf_provider=aws,
name="/app/db/password",
type="SecureString",
value_wo=temp_secret.output.random_password,
value_wo_version=1,
)
(Generated provider packages expose typed *EphemeralResource classes when the provider
schema defines ephemeral resources.)
Output
An Output exposes a value from a Stack after apply, makes it inspectable in plan
summaries, and persists it in state under <stack>.output.<id>.
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
Any |
(required) | Literal value, RuntimeValue, f-string, or collection of runtime values. Ephemeral values are refused. |
description |
str \| None |
None |
Human-readable documentation for the output. |
sensitive |
bool |
False |
Marks the output sensitive: shown as (sensitive value) in plans and [secret] in apply summaries/JSON unless --show-secrets is passed. |
Key behaviors
- Outputs are graph nodes: Evaluated once all referenced resources are planned/applied.
- Output changes appear in plans: Created, updated, deleted, or sensitivity-changed
outputs appear under
Changes to Outputs. A plan that changes outputs alone still counts as a change requiring approval. - Reading outputs programmatically: In
nf.sdk,run.outputs()returns a mapping of<stack>.<output_name>to resolved values ([secret]for sensitive outputs unless revealed). - Cross-stack references: Prefer referencing constructs directly in Python
(
network.vpc.output.id) across stacks in the sameApprather than indirection throughOutputstrings; useOutputto publish values for operators, CI, andnf.sdkcallers.
# coding: nf_autoid
from nf.core import App, Bind, BindContext, GeneratedValue, Output, Stack
with App(nf_id="outputs-demo") as app, Stack() as app_stack, BindContext:
token: Bind = GeneratedValue(generator="hex", params={"length": 24})
api_token: Bind = Output(
value=token.result,
description="Generated API signing token",
sensitive=True,
)