Target-Based Configuration System - Complete Implementation
Version: 4.0.0 Date: 2025-10-06 Status: β PRODUCTION READY
Executive Summary
A comprehensive target-based configuration system has been successfully implemented, replacing the monolithic config.defaults.toml with a modular, workspace-centric architecture. Each provider, platform service, and KMS component now has independent configuration, and workspaces are fully self-contained with their own config/provisioning.yaml.
π― Objectives Achieved
β
Independent Target Configs: Providers, platform services, and KMS have separate configs
β
Workspace-Centric: Each workspace has complete, self-contained configuration
β
User Context Priority: ws_{name}.yaml files provide high-priority overrides
β
No Runtime config.defaults.toml: Template-only, never loaded at runtime
β
Migration Automation: Safe migration scripts with dry-run and backup
β
Schema Validation: Comprehensive validation for all config types
β
CLI Integration: Complete command suite for config management
β
Legacy Nomenclature: All cn_provisioning/kloud references updated
π Architecture Overview
Configuration Hierarchy (Priority: Low β High)
1. Workspace Config workspace/{name}/config/provisioning.yaml
2. Provider Configs workspace/{name}/config/providers/*.toml
3. Platform Configs workspace/{name}/config/platform/*.toml
4. User Context ~/Library/Application Support/provisioning/ws_{name}.yaml
5. Environment Variables PROVISIONING_*
Directory Structure
workspace/{name}/
βββ config/
β βββ provisioning.yaml # Main workspace config (YAML)
β βββ providers/
β β βββ aws.toml # AWS provider config
β β βββ upcloud.toml # UpCloud provider config
β β βββ local.toml # Local provider config
β βββ platform/
β β βββ orchestrator.toml # Orchestrator service config
β β βββ control-center.toml # Control Center config
β β βββ mcp-server.toml # MCP Server config
β βββ kms.toml # KMS configuration
βββ infra/ # Infrastructure definitions
βββ .cache/ # Cache directory
βββ .runtime/ # Runtime data
βββ .providers/ # Provider-specific runtime
βββ .orchestrator/ # Orchestrator data
βββ .kms/ # KMS keys and cache
π Implementation Details
Phase 1: Nomenclature Migration β
Files Updated: 9 core files (29+ changes)
Mappings:
cn_provisioningβprovisioningkloudβworkspacekloud_pathβworkspace_pathkloud_listβworkspace_listdflt_setβdefault_settingsPROVISIONING_KLOUD_PATHβPROVISIONING_WORKSPACE_PATH
Files Modified:
lib_provisioning/defs/lists.nulib_provisioning/sops/lib.nulib_provisioning/kms/lib.nulib_provisioning/cmd/lib.nulib_provisioning/config/migration.nulib_provisioning/config/loader.nulib_provisioning/config/accessor.nulib_provisioning/utils/settings.nutemplates/default_context.yaml
Phase 2: Independent Target Configs β
2.1 Provider Configs
Files Created: 6 files (3 providers Γ 2 files each)
| Provider | Config | Schema | Features |
|---|---|---|---|
| AWS | extensions/providers/aws/config.defaults.toml | config.schema.toml | CLI/API, multi-auth, cost tracking |
| UpCloud | extensions/providers/upcloud/config.defaults.toml | config.schema.toml | API-first, firewall, backups |
| Local | extensions/providers/local/config.defaults.toml | config.schema.toml | Multi-backend (libvirt/docker/podman) |
Interpolation Variables: {{workspace.path}}, {{provider.paths.base}}
2.2 Platform Service Configs
Files Created: 10 files
| Service | Config | Schema | Integration |
|---|---|---|---|
| Orchestrator | platform/orchestrator/config.defaults.toml | config.schema.toml | Rust config loader (src/config.rs) |
| Control Center | platform/control-center/config.defaults.toml | config.schema.toml | Enhanced with workspace paths |
| MCP Server | platform/mcp-server/config.defaults.toml | config.schema.toml | New configuration |
Orchestrator Rust Integration:
- Added
tomldependency toCargo.toml - Created
src/config.rs(291 lines) - CLI args override config values
2.3 KMS Config
Files Created: 6 files (2,510 lines total)
core/services/kms/config.defaults.toml(270 lines)core/services/kms/config.schema.toml(330 lines)core/services/kms/config.remote.example.toml(180 lines)core/services/kms/config.local.example.toml(290 lines)core/services/kms/README.md(500+ lines)core/services/kms/MIGRATION.md(800+ lines)
Key Features:
- Three modes: local, remote, hybrid
- 59 new accessor functions in
config/accessor.nu - Secure defaults (TLS 1.3, 0600 permissions)
- Comprehensive security validation
Phase 3: Workspace Structure β
3.1 Workspace-Centric Architecture
Template Files Created: 7 files
config/templates/workspace-provisioning.yaml.templateconfig/templates/provider-aws.toml.templateconfig/templates/provider-local.toml.templateconfig/templates/provider-upcloud.toml.templateconfig/templates/kms.toml.templateconfig/templates/user-context.yaml.templateconfig/templates/README.md
Workspace Init Module: lib_provisioning/workspace/init.nu
Functions:
workspace-init- Initialize complete workspace structureworkspace-init-interactive- Interactive creation wizardworkspace-list- List all workspacesworkspace-activate- Activate a workspaceworkspace-get-active- Get currently active workspace
3.2 User Context System
User Context Files: ~/Library/Application Support/provisioning/ws_{name}.yaml
Format:
workspace:
name: "production"
path: "/path/to/workspace"
active: true
overrides:
debug_enabled: false
log_level: "info"
kms_mode: "remote"
# ... 9 override fields total
Functions Created:
create-workspace-context- Create ws_{name}.yamlset-workspace-active- Mark workspace as activelist-workspace-contexts- List all contextsget-active-workspace-context- Get active workspaceupdate-workspace-last-used- Update timestamp
Helper Functions: lib_provisioning/workspace/helpers.nu
apply-context-overrides- Apply overrides to configvalidate-workspace-context- Validate context structurehas-workspace-context- Check context existence
3.3 Workspace Activation
CLI Flags Added:
--activate (-a)- Activate workspace on creation--interactive (-I)- Interactive creation wizard
Commands:
# Create and activate
provisioning workspace init my-app ~/workspaces/my-app --activate
# Interactive mode
provisioning workspace init --interactive
# Activate existing
provisioning workspace activate my-app
Phase 4: Configuration Loading β
4.1 Config Loader Refactored
File: lib_provisioning/config/loader.nu
Critical Changes:
- β REMOVED:
get-defaults-config-path()function - β
ADDED:
get-active-workspace()function - β
ADDED:
apply-user-context-overrides()function - β ADDED: YAML format support
New Loading Sequence:
- Get active workspace from user context
- Load
workspace/{name}/config/provisioning.yaml - Load provider configs from
workspace/{name}/config/providers/*.toml - Load platform configs from
workspace/{name}/config/platform/*.toml - Load user context
ws_{name}.yaml(stored separately) - Apply user context overrides (highest config priority)
- Apply environment-specific overrides
- Apply environment variable overrides (highest priority)
- Interpolate paths
- Validate configuration
4.2 Path Interpolation
Variables Supported:
{{workspace.path}}- Active workspace base path{{workspace.name}}- Active workspace name{{provider.paths.base}}- Provider-specific paths{{env.*}}- Environment variables (safe list){{now.date}},{{now.timestamp}},{{now.iso}}- Date/time{{git.branch}},{{git.commit}}- Git info{{path.join(...)}}- Path joining function
Implementation: Already present in loader.nu (lines 698-1262)
Phase 5: CLI Commands β
Module Created: lib_provisioning/workspace/config_commands.nu (380 lines)
Commands Implemented:
# Show configuration
provisioning workspace config show [name] [--format yaml|json|toml]
# Validate configuration
provisioning workspace config validate [name]
# Generate provider config
provisioning workspace config generate provider <name>
# Edit configuration
provisioning workspace config edit <type> [name]
# Types: main, provider, platform, kms
# Show hierarchy
provisioning workspace config hierarchy [name]
# List configs
provisioning workspace config list [name] [--type all|provider|platform|kms]
Help System Updated: main_provisioning/help_system.nu
Phase 6: Migration & Validation β
6.1 Migration Script
File: scripts/migrate-to-target-configs.nu (200+ lines)
Features:
- Automatic detection of old
config.defaults.toml - Workspace structure creation
- Config transformation (TOML β YAML)
- Provider config generation from templates
- User context creation
- Safety features:
--dry-run,--backup, confirmation prompts
Usage:
# Dry run
./scripts/migrate-to-target-configs.nu --workspace-name "prod" --dry-run
# Execute with backup
./scripts/migrate-to-target-configs.nu --workspace-name "prod" --backup
6.2 Schema Validation
Module: lib_provisioning/config/schema_validator.nu (150+ lines)
Validation Features:
- Required fields checking
- Type validation (string, int, bool, record)
- Enum value validation
- Numeric range validation (min/max)
- Pattern matching with regex
- Deprecation warnings
- Pretty-printed error messages
Functions:
# Generic validation
validate-config-with-schema $config $schema_file
# Domain-specific
validate-provider-config "aws" $config
validate-platform-config "orchestrator" $config
validate-kms-config $config
validate-workspace-config $config
Test Suite: tests/config_validation_tests.nu (200+ lines)
π Statistics
Files Created
| Category | Count | Total Lines |
|---|---|---|
| Provider Configs | 6 | 22,900 bytes |
| Platform Configs | 10 | ~1,500 lines |
| KMS Configs | 6 | 2,510 lines |
| Workspace Templates | 7 | ~800 lines |
| Migration Scripts | 1 | 200+ lines |
| Validation System | 2 | 350+ lines |
| CLI Commands | 1 | 380 lines |
| Documentation | 15+ | 8,000+ lines |
| TOTAL | 48+ | ~13,740 lines |
Files Modified
| Category | Count | Changes |
|---|---|---|
| Core Libraries | 8 | 29+ occurrences |
| Config Loader | 1 | Major refactor |
| Context System | 2 | Enhanced |
| CLI Integration | 5 | Flags & commands |
| TOTAL | 16 | Significant |
π Key Features
1. Independent Configuration
β Each provider has own config β Each platform service has own config β KMS has independent config β No shared monolithic config
2. Workspace Self-Containment
β Each workspace has complete config β No dependency on global config β Portable workspace directories β Easy backup/restore
3. User Context Priority
β Per-workspace overrides β Highest config file priority β Active workspace tracking β Last used timestamp
4. Migration Safety
β Dry-run mode β Automatic backups β Confirmation prompts β Rollback procedures
5. Comprehensive Validation
β Schema-based validation β Type checking β Pattern matching β Deprecation warnings
6. CLI Integration
β Workspace creation with activation β Interactive mode β Config management commands β Validation commands
π Documentation
Created Documentation
- Architecture:
docs/configuration/workspace-config-architecture.md - Migration Guide:
docs/MIGRATION_GUIDE.md - Validation Guide:
docs/CONFIG_VALIDATION.md - Migration Example:
docs/MIGRATION_EXAMPLE.md - CLI Commands:
docs/user/workspace-config-commands.md - KMS README:
core/services/kms/README.md - KMS Migration:
core/services/kms/MIGRATION.md - Platform Summary:
platform/PLATFORM_CONFIG_SUMMARY.md - Workspace Implementation:
docs/WORKSPACE_CONFIG_IMPLEMENTATION_SUMMARY.md - Template Guide:
config/templates/README.md
π§ͺ Testing
Test Suites Created
-
Config Validation Tests:
tests/config_validation_tests.nu- Required fields validation
- Type validation
- Enum validation
- Range validation
- Pattern validation
- Deprecation warnings
-
Workspace Verification:
lib_provisioning/workspace/verify.nu- Template directory checks
- Template file existence
- Module loading verification
- Config loader validation
Running Tests
# Run validation tests
nu tests/config_validation_tests.nu
# Run workspace verification
nu lib_provisioning/workspace/verify.nu
# Validate specific workspace
provisioning workspace config validate my-app
π Migration Path
Step-by-Step Migration
-
Backup
cp -r provisioning/config provisioning/config.backup.$(date +%Y%m%d) -
Dry Run
./scripts/migrate-to-target-configs.nu --workspace-name "production" --dry-run -
Execute Migration
./scripts/migrate-to-target-configs.nu --workspace-name "production" --backup -
Validate
provisioning workspace config validate -
Test
provisioning --check server list -
Clean Up
# Only after verifying everything works rm provisioning/config/config.defaults.toml
β οΈ Breaking Changes
Version 4.0.0 Changes
-
config.defaults.toml is template-only
- Never loaded at runtime
- Used only to generate workspace configs
-
Workspace required
- Must have active workspace
- Or be in workspace directory
-
Environment variables renamed
PROVISIONING_KLOUD_PATHβPROVISIONING_WORKSPACE_PATHPROVISIONING_DFLT_SETβPROVISIONING_DEFAULT_SETTINGS
-
User context location
~/Library/Application Support/provisioning/ws_{name}.yaml- Not
default_context.yaml
π― Success Criteria
All success criteria MET β :
- β Zero occurrences of legacy nomenclature
- β Each provider has independent config + schema
- β Each platform service has independent config
- β KMS has independent config (local/remote)
- β Workspace creation generates complete config structure
- β
User context system
ws_{name}.yamlfunctional - β
provisioning workspace create --activateworks - β Config hierarchy respected correctly
- β
paths.baseadjusts dynamically per workspace - β Migration script tested and functional
- β Documentation complete
- β Tests passing
π Support
Common Issues
Issue: βNo active workspace foundβ Solution: Initialize or activate a workspace
provisioning workspace init my-app ~/workspaces/my-app --activate
Issue: βConfig file not foundβ Solution: Ensure workspace is properly initialized
provisioning workspace config validate
Issue: βOld config still being loadedβ Solution: Verify config.defaults.toml is not in runtime path
# Check loader.nu - get-defaults-config-path should be REMOVED
grep "get-defaults-config-path" lib_provisioning/config/loader.nu
# Should return: (empty)
Getting Help
# General help
provisioning help
# Workspace help
provisioning help workspace
# Config commands help
provisioning workspace config help
π Conclusion
The target-based configuration system is complete, tested, and production-ready. It provides:
- Modularity: Independent configs per target
- Flexibility: Workspace-centric with user overrides
- Safety: Migration scripts with dry-run and backups
- Validation: Comprehensive schema validation
- Usability: Complete CLI integration
- Documentation: Extensive guides and examples
All objectives achieved. System ready for deployment.
Maintained By: Infrastructure Team Version: 4.0.0 Status: β Production Ready Last Updated: 2025-10-06