Skip to content

Test an app without cloud credentials

In this tutorial you will write a StorageStack and verify its resource arguments, provider wiring, and output references offline using pytest—with no AWS credentials, provider binaries, or Terraform installation.

Before you start: Install netherframe.cli (or netherframe.core) and AWS bindings. See Install Netherframe.


Step 1: Install pytest

uv add --dev pytest

Step 2: Define the stack in infra.py

from nf.core import App, Output, Stack
from nf.providers.hashicorp.aws import AwsProvider, S3Bucket


class StorageStack(Stack):
    def __init__(self, *, nf_scope: App, nf_id: str, bucket_name: str) -> None:
        super().__init__(nf_scope=nf_scope, nf_id=nf_id)
        provider = AwsProvider(nf_scope=self, nf_id="aws", region="us-east-1")
        assets = S3Bucket(
            nf_scope=self,
            nf_id="assets",
            nf_provider=provider,
            bucket=bucket_name,
            tags={"Purpose": "assets"},
        )
        Output(nf_scope=self, nf_id="bucket_id", value=assets.output.id)

Step 3: Write the offline test in test_infra.py

Create a fresh App in each test and synthesize into pytest's tmp_path directory:

import json

from infra import StorageStack
from nf.core import App


def test_storage_configuration(tmp_path):
    app = App(nf_id="test")
    StorageStack(nf_scope=app, nf_id="storage", bucket_name="docs-example-assets")
    app.synth(outdir=tmp_path)

    config = json.loads((tmp_path / "test" / "storage" / "nf.tf.json").read_text())
    bucket = config["resource"]["aws_s3_bucket"]["assets"]
    assert bucket["bucket"] == "docs-example-assets"
    assert bucket["tags"] == {"Purpose": "assets"}
    assert bucket["provider"] == "aws"
    assert config["output"]["bucket_id"]["value"] == "${aws_s3_bucket.assets.id}"

Because app.synth(...) serializes the construct graph locally, "docs-example-assets" does not need to exist in AWS.


Step 4: Run the test and verify it catches regressions

uv run pytest test_infra.py

Expect 1 passed. Temporarily change tags={"Purpose": "assets"} in infra.py to tags={"Purpose": "other"} and re-run uv run pytest test_infra.py to confirm the test catches the drift, then restore "assets".


Next steps