Skip to content

Backend Bootstrapping in Netherframe

Netherframe supports explicit backend bootstrapping. The settings choose a backend (or the code names one), then a bootstrap workflow creates the infrastructure it needs, such as an S3 bucket or DynamoDB table.

Nothing creates backend resources implicitly. nf backend bootstrap creates them, and, with the opt-in bootstrap_backend setting, so does the first hybrid apply that needs them (see Creating it on the first apply). Synthesis never does.

Current Support

This page tracks the backends and features that are supported today in the current implementation.

Backend / flow Detection and config Explicit bootstrap Explicit validation Notes
local Supported in core Not needed Not implemented as a separate remote-resource check Default fallback backend
s3 Supported in core Supported Supported Requires the AWS backend package so the S3 backend and bootstrapper are registered
BackendChain Supported in core Supported when the selected backend exposes a bootstrapper Supported on the same basis Useful for s3 -> local style fallback flows
Other backend types Extension point only Depends on external package Depends on external package Not documented here as current built-in support

Two important boundaries:

  • Core auto-detection currently knows local and s3.
  • Names such as gcs and azurerm still appear in some registry and CLI extension points, but Netherframe does not currently document them here as shipped bootstrapping support.

How Bootstrapping Works

1. The Backend

A stack whose code assigns no backend, and a hybrid app whose code names no state backend, get the backend the settings choose, read each time (nothing is saved):

  1. a backend the code names is kept
  2. otherwise the settings choose it: backend_type and its options (nf --backend-type, or [tool.nf.config])
  3. otherwise it is local

nf backend show shows it, where each value came from, and where states go.

2. Its Options

The settings give these options:

  • local: backend_local_path, the state file (else .nf.out/nf.tfstate for a hybrid app, Terraform's own file in each legacy stack's directory)
  • s3: backend_s3_bucket, backend_s3_region (else AWS_DEFAULT_REGION), backend_s3_profile (else the AWS SDK's credential chain) and backend_s3_key_prefix: a hybrid app's state is PREFIX/nf.tfstate, a legacy stack's PREFIX/STACK/terraform.tfstate

A backend with other options (a lock table, a KMS key, another type) is named in code: an S3Backend(...) on the stack, or app.enable_hybrid_execution(state_backend=...).

3. Bootstrap Explicitly When Needed

Bootstrapping is an explicit operation. Use one of these flows:

  • nf backend bootstrap
  • BackendChain.bootstrap_resources(...)
  • a backend-specific bootstrapper such as S3BackendBootstrapper

If a backend does not expose a bootstrapper, Netherframe reports that as unsupported instead of attempting implicit creation.

Supported Usage Patterns

Local Backend

Local is the default fallback when no remote backend config is available.

from nf.core import App, LocalBackend, Stack

app = App(nf_id="app")
stack = Stack(nf_scope=app, nf_id="my-stack")

backend = LocalBackend(
    nf_scope=stack,
    nf_id="local-backend",
    path="./terraform.tfstate",
)

Local backends do not need a bootstrap step.

S3 Backend with Explicit Bootstrap

Use the AWS backend package when you want an S3 backend and S3 bootstrapper:

from nf.core import App, Stack
from nf.backends.aws import S3Backend, S3BackendBootstrapper

app = App(nf_id="app")
stack = Stack(nf_scope=app, nf_id="my-stack")

bootstrapper = S3BackendBootstrapper(
    bucket_name="my-state-bucket",
    region="us-west-2",
    dynamodb_table="my-state-locks",
    encrypt=True,
)


def bootstrap_if_missing() -> None:
    # Calls AWS, so it needs credentials
    if not bootstrapper.validate():
        bootstrapper.bootstrap()


backend = S3Backend(
    nf_scope=stack,
    nf_id="s3-backend",
    bucket="my-state-bucket",
    key="prod/terraform.tfstate",
    region="us-west-2",
    dynamodb_table="my-state-locks",
    encrypt=True,
)

Terraform backend configuration still requires literal values. Resource output references are not valid backend config values during synthesis.

BackendChain

BackendChain lets you pick a backend at runtime and bootstrap the selected backend when that backend supports it.

from nf.backends.aws import S3Backend
from nf.core import App, BackendChain, BackendSettings, LocalBackend, Stack
from nf.core.constructs.backend_base import Backend

app = App(nf_id="app")
stack = Stack(nf_scope=app, nf_id="my-stack")
backend = BackendChain(
    nf_scope=stack,
    nf_id="backend",
    backends=[
        S3Backend(nf_scope=stack, nf_id="s3", bucket="my-state-bucket", nf_backend_settings=BackendSettings(register=False)),
        LocalBackend(nf_scope=stack, nf_id="local", nf_backend_settings=BackendSettings(register=False)),
    ],
)


def bootstrap() -> None:
    # Checks for the bucket, so it needs AWS credentials
    decision = backend.resolve()
    result = backend.bootstrap_resources(
        policy=Backend.BootstrapPolicy.IF_MISSING,
        dry_run=False,
    )

    print(decision.backend.backend_type)
    print(result.action)

Bootstrapping is skipped when the eligible backend depends on in-stack Resource objects rather than literal config.

CLI Behavior Today

nf backend show

The backend the settings choose, where each value came from (a flag, [tool.nf.config], AWS_DEFAULT_REGION) and where a hybrid app's and a legacy stack's state go:

nf backend show
nf --backend-type s3 --backend-s3-bucket my-state-bucket --backend-s3-region us-east-1 backend show

nf backend bootstrap

Bootstrap runs against that backend through BackendChain.

nf backend bootstrap
nf backend bootstrap --dry-run
nf backend bootstrap --force
nf backend bootstrap --tag Team=platform --tag Project=myapp

Outcomes:

  • s3: bootstraps or validates via the registered S3 bootstrapper
  • local: reports that bootstrapping is not required / not supported
  • unsupported backend types: reports UNSUPPORTED

nf backend validate

Validation uses the same backend and only performs meaningful remote-resource validation for backends that expose a bootstrapper. It exits 1 when the resources are missing.

nf backend validate

Backend Settings

Give the backend with these settings, as keys of [tool.nf.config] or flags of nf (before or after the command). Nothing is read from the environment but the AWS SDK's own AWS_DEFAULT_REGION.

[tool.nf.config]
backend_type = "s3"
backend_s3_bucket = "my-state-bucket"
backend_s3_key_prefix = "myapp"
backend_s3_region = "us-east-1"  # else AWS_DEFAULT_REGION
backend_s3_profile = "platform-state"  # else the AWS SDK's credential chain

# Or a local file
# backend_type = "local"
# backend_local_path = "state/myapp.tfstate"

The same as flags, for one run: the hybrid app web keeps its state at s3://my-state-bucket/myapp/nf.tfstate.

nf --backend-type s3 --backend-s3-bucket my-state-bucket \
  --backend-s3-key-prefix myapp --backend-s3-region us-east-1 apply --app web

See Settings.

Creating It On The First Apply

[tool.nf.config]
backend_type = "s3"
backend_s3_bucket = "acme-site-state"
backend_s3_region = "eu-west-1"
bootstrap_backend = true
# bootstrap_backend_provider = "network.aws"  # else the app's own (unaliased) aws configuration

A hybrid run checks, reading only, whether the bucket and its lock table exist. If they do, nothing else happens: no provider starts, and no create permission is needed. If they do not:

  • nf plan plans against empty state, without a lock, and notes that the apply creates the backend; a plan saved then (--out) applies once it exists.
  • nf apply creates them before taking the lock, through the app's own hashicorp/aws configuration (its credentials, profile and assumed role) in the backend's region, and only as the account the backend reads and writes state as. It says what it created.

The provider's settings must be known before any state exists: settings that read state or data sources are refused; name a configuration with static settings in bootstrap_backend_provider.

Bootstrapping S3

The S3 bootstrapper creates the bucket, its versioning and encryption, and the DynamoDB table with the hashicorp/aws provider. It runs the newest aws provider already in the provider cache (usually the one the app itself uses), else the latest release. Pin a version or constraint with nf backend bootstrap --aws-provider-version, bootstrap_aws_provider_version in [tool.nf.config], provider_version= on S3BackendBootstrapper, or bootstrap_provider_version on the S3 backend, in that order of precedence.

For example, S3Backend(..., bootstrap_provider_version="~> 6.0") pins the bootstrap provider. This setting survives backend configuration serialization and is omitted from the Terraform backend configuration.

Best Practices

1. Use Explicit Bootstrap for Remote State

For S3, treat backend creation as a separate setup step:

nf backend show
nf backend bootstrap
nf backend validate

2. Tag Remote Backend Resources

If you use S3 bootstrapping, include ownership and environment tags so the state bucket and lock table are discoverable and auditable.

3. Separate State by Environment

Use distinct S3 buckets or key prefixes for development, staging, and production state.

4. Use DynamoDB Locking with S3

When you use S3 as a shared backend, prefer a DynamoDB table for state locking to prevent concurrent writes.

Troubleshooting

nf backend bootstrap reports unsupported

Check:

  • the configured backend type is one that currently exposes a bootstrapper
  • the required backend package is installed and registered
  • the backend does not depend on in-stack Resource objects for values that must be literal during bootstrap

nf backend validate reports unsupported for local

That is expected. Local backends do not require remote resource validation.

S3 permission failures

Confirm the AWS identity used for bootstrapping can create and inspect the S3 bucket and optional DynamoDB table.

Extension Backends

Netherframe does have extension points for additional backends:

  • backend construct registration
  • backend factories
  • backend bootstrappers

Those extension hooks are real, but this page intentionally documents only the backends and bootstrap flows that are currently supported and tracked in the main implementation.