Skip to content

S3 Backend Unification Plan

Overview

We're unifying the S3 backend into a single S3Backend class that adapts its behavior based on the execution mode. This is a breaking change: S3StateBackend is removed.

Benefits

  1. Single API: Users don't need to know about two different classes
  2. Cleaner imports: Just from nf.backends.aws import S3Backend
  3. Easier maintenance: One implementation to maintain
  4. Mode detection: Can automatically detect synthesis vs native mode

Migration Steps

Phase 1: Update the S3Backend Implementation

  1. Replace the current s3.py with the unified implementation
  2. Remove S3StateBackend and update imports

Phase 2: Update Internal Usage

  1. state_engine_factory.py: Update to use unified S3Backend
# Before
from nf.backends.aws import S3Backend

backend_instance = S3Backend.for_native(...)

# After
from nf.backends.aws import S3Backend

backend_instance = S3Backend.for_native(...)
  1. app_stack.py: Already uses S3Backend, just ensure it works with unified version

  2. Tests: Update test imports and initialization

Phase 3: Documentation Updates

  1. Update documentation to explain the unified backend
  2. Add migration guide for users

Usage Examples

Synthesis Mode (Terraform)

# Automatic mode detection when scope is provided
backend = S3Backend(nf_scope=stack, bucket="my-state-bucket", key="terraform.tfstate")

# Or explicit
backend = S3Backend.for_synthesis(nf_scope=stack, bucket="my-state-bucket", key="terraform.tfstate")

# Bootstrap resources explicitly
bootstrapper = S3BackendBootstrapper(
    bucket_name="my-state-bucket",
    region="us-east-1",
    dynamodb_table="my-lock-table",
)
bootstrapper.bootstrap()

Native Mode

# Automatic mode detection when hybrid_mode=True
backend = S3Backend(bucket="my-state-bucket", key="terraform.tfstate", region="us-east-1", hybrid_mode=True)

# Or explicit
backend = S3Backend.for_native(bucket="my-state-bucket", key="terraform.tfstate", region="us-east-1")

Breaking Change

  • S3StateBackend is removed. Use S3Backend with for_native(...) or hybrid_mode=True.

Testing Strategy

  1. Run all existing tests to ensure backward compatibility
  2. Add new tests for unified behavior
  3. Test mode detection logic
  4. Ensure both synthesis and native modes work correctly