Skip to content

Adopt an existing bucket

Bring one existing S3 bucket into a hybrid app through a reviewed import plan. This walkthrough models an object that is already running; it does not discover an entire account.

Before you start: install Netherframe and AWS bindings, choose a bucket you intend to manage, and use credentials that can read it. Applying any configuration changes shown by the plan requires the corresponding AWS permissions. Run the commands with the project's Python environment active. If the bucket is already owned by a Terraform state, use conversion and Terraform-state adoption instead.

1. Identify the object and region

Note the actual bucket name and its region. The app takes them as inputs, given on the command line as ++bucket=your-existing-bucket-name ++region=us-east-1 (see nf vars).

These values identify the object. They do not provide credentials; the AWS provider uses its configured credential chain. Use the same account during plan and apply; a saved plan records the inputs it was made with.

2. Model the bucket and request its import

Create app.py:

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


def app(bucket: str, region: str = "us-east-1") -> App:
    adoption = App(nf_id="adoption-demo")
    stack = Stack(nf_scope=adoption, nf_id="storage")
    provider = AwsProvider(nf_scope=stack, nf_id="aws", region=region)
    S3Bucket(nf_scope=stack, nf_id="existing", nf_provider=provider, bucket=bucket).import_from(bucket)
    adoption.enable_hybrid_execution_local(path=".nf.out/adoption.tfstate")
    return adoption

Add or update your project's CLI configuration:

[tool.nf]
apps = ["app:app"]

3. Plan and review the import

nf plan --app app ++bucket=your-existing-bucket-name ++region=us-east-1 \
  --adopt-missing error --out reviewed-import.json

Look for an import of storage.aws_s3_bucket.existing from the bucket name. The plan may also contain updates if the code and provider view differ. Review those differences before applying; an import can be followed by a normal update or replacement.

--adopt-missing error makes a missing target fail instead of being created. If planning fails because the object cannot be read, correct the identity or access problem before continuing.

4. Apply the saved plan and verify

nf apply --app app --plan-file reviewed-import.json
nf plan --app app ++bucket=your-existing-bucket-name ++region=us-east-1

--plan-file builds the app with the inputs the plan was made with. Approve the import and any reviewed configuration changes. The bucket is now recorded in nf state. If the configuration matches, the next plan should have no resource changes. The leftover import_from request is no longer needed once adoption has completed.

Next: inspect state, review changes in CI, or discover and codify a Keycloak realm.

Understand adoption

An import request is explicit ownership

Declaring a resource with a matching name does not by itself adopt an existing object. import_from(name) asks the provider to read that object and lets the plan show how it will be managed. Applying the import writes its record into state.

Resources can also request adoption by identity with LifecycleRules(adopt=True) or adopt="required". A run can supply an adoption manifest without changing the Python source. Read the adoption guide for precedence, missing-object behavior and duplicate protection.

Discovery helps build a model

For a larger estate, start by listing the available discovery integrations:

nf discover list providers
nf discover list resource-types aws --filter "aws_*"

Discovery inventories live objects; codification can generate starting code and manifests where the integration supports it. Review the generated coverage and omissions rather than assuming every object or provider feature can be represented. Continue with discovery, import and drift.

Automation still needs import approval

For unattended runs, --auto-approve alone does not approve imports. Add --approve-imports only when the job's review process authorizes adoption. Saved plans retain import requests and the policies used to resolve them.

Recovery does not treat an import as a new cloud object

Rollback of a failed apply removes adopted objects from nf state while leaving the objects in place. It cannot undo a completed update to an imported object. See rollback and recovery before a production cutover.