Create a multi-stack app
In this tutorial you will organize AWS infrastructure into two distinct stacks—network
and storage—inside a single Netherframe app, then plan, apply, verify convergence, and
destroy both stacks together.
Before you start: Complete Tutorial 1: Run your first hybrid app,
install the AWS bindings (uv add netherframe.providers.hashicorp.aws or
generate them), and configure AWS credentials for your
sandbox account. Pick a globally unique S3 bucket name before running nf apply.
Step 1: Set up the project layout
Create a new directory with two files:
my-infra/
pyproject.toml
app.py
Add the app registration to pyproject.toml:
[tool.nf]
apps = ["app:app"]
Step 2: Define the network and storage stacks
Write app.py using @autoscope so each Stack subclass automatically becomes the scope
for the providers, resources, and outputs created in its __init__:
# coding: nf_autoid
from nf.core import App, Bind, BindContext, Output, Stack, autoscope
from nf.providers.hashicorp.aws import AwsProvider, S3Bucket, Subnet, Vpc
@autoscope
class NetworkStack(Stack):
def __init__(self, *, nf_scope: App | None = None, nf_id: str | None = None, region: str) -> None:
super().__init__(nf_scope=nf_scope, nf_id=nf_id)
aws: Bind = AwsProvider(region=region)
self.vpc: Bind[Vpc] = Vpc(
cidr_block="10.0.0.0/16",
enable_dns_support=True,
enable_dns_hostnames=True,
)
self.public_subnet: Bind[Subnet] = Subnet(
vpc_id=self.vpc.output.id,
cidr_block="10.0.1.0/24",
availability_zone=f"{region}a",
map_public_ip_on_launch=True,
)
vpc_id: Bind = Output(value=self.vpc.output.id)
@autoscope
class StorageStack(Stack):
def __init__(self, *, nf_scope: App | None = None, nf_id: str | None = None, region: str) -> None:
super().__init__(nf_scope=nf_scope, nf_id=nf_id)
aws: Bind = AwsProvider(region=region)
self.bucket: S3Bucket = S3Bucket(
nf_id="assets",
bucket="replace-with-a-globally-unique-name",
force_destroy=True,
)
bucket_id: Bind = Output(value=self.bucket.output.id)
with App(nf_id="platform") as app, BindContext:
network: Bind = NetworkStack(region="us-east-1")
storage: Bind = StorageStack(region="us-east-1")
app.enable_hybrid_execution_local(path=".nf.out/hybrid.tfstate")
Replace "replace-with-a-globally-unique-name" with a unique bucket name you own. Notice
that self.bucket passes nf_id="assets" explicitly so its state address
(storage.aws_s3_bucket.assets) stays stable even if the Python attribute is renamed.
Step 3: Save and review the whole-app plan
nf plan --app app --out reviewed-plan.json
The plan groups changes under both network and storage in one artifact:
network.aws_vpc.vpcnetwork.aws_subnet.public_subnetstorage.aws_s3_bucket.assets
Step 4: Apply, check convergence, and clean up
nf apply --app app --plan-file reviewed-plan.json
nf plan --app app
Approve the apply with yes. The second nf plan should report no changes.
When you are done, remove all created AWS resources:
nf destroy --app app
Next steps
- Extract reusable modules: Build your first reusable construct or Organize a Netherframe project.
- Test offline without AWS credentials: Test an app without cloud credentials.
- Understand cross-stack dependencies: Cross-stack references.