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
- Single API: Users don't need to know about two different classes
- Cleaner imports: Just
from nf.backends.aws import S3Backend - Easier maintenance: One implementation to maintain
- Mode detection: Can automatically detect synthesis vs native mode
Migration Steps
Phase 1: Update the S3Backend Implementation
- Replace the current
s3.pywith the unified implementation - Remove
S3StateBackendand update imports
Phase 2: Update Internal Usage
- 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(...)
-
app_stack.py: Already uses S3Backend, just ensure it works with unified version
-
Tests: Update test imports and initialization
Phase 3: Documentation Updates
- Update documentation to explain the unified backend
- 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
S3StateBackendis removed. UseS3Backendwithfor_native(...)orhybrid_mode=True.
Testing Strategy
- Run all existing tests to ensure backward compatibility
- Add new tests for unified behavior
- Test mode detection logic
- Ensure both synthesis and native modes work correctly