Architecture¶
This document describes the architecture and implementation details of the TofuSoup Terraform provider.
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
Overview¶
The TofuSoup provider is built using the Pyvider framework, enabling Python-based Terraform provider development with modern async capabilities.
Core Technologies¶
Pyvider Framework¶
- Purpose: Python framework for building Terraform providers
- Features: Schema system, async base classes, resource management
- Benefits: Rapid development, type safety, Python ecosystem access
FlavorPack (PSPF/2025)¶
- Purpose: Binary packaging and multi-platform executable generation
- Features: Cross-platform binaries, self-contained executables
- Output:
terraform-provider-tofusoupexecutable for macOS, Linux, Windows
Plating¶
- Purpose: Automated documentation generation from code
- Features: Extracts docstrings, generates markdown, creates mkdocs sites
- Benefits: Always up-to-date documentation, consistent formatting
TofuSoup¶
- Purpose: Async registry client and state inspection utilities
- Features: Terraform/OpenTofu registry APIs, state file parsing
- Benefits: High-performance async operations, robust error handling
Testing¶
- Framework: pytest + pytest-asyncio
- Coverage: 280 comprehensive tests
- Approach: Unit tests, integration tests, async test patterns
Project Structure¶
terraform-provider-tofusoup/
โโโ src/tofusoup/tf/components/
โ โโโ provider.py # Provider configuration
โ โโโ data_sources/ # All 9 data sources
โ โโโ provider_info.py
โ โโโ provider_versions.py
โ โโโ module_info.py
โ โโโ module_versions.py
โ โโโ module_search.py
โ โโโ registry_search.py
โ โโโ state_info.py
โ โโโ state_resources.py
โ โโโ state_outputs.py
โโโ tests/ # 280 comprehensive tests
โโโ examples/ # Working examples for all data sources
โโโ docs/ # Generated documentation
Component Architecture¶
Provider Configuration¶
The provider (provider.py) defines global configuration:
- cache_dir: Cache directory for registry queries
- cache_ttl_hours: Cache time-to-live in hours
@provider(name="tofusoup")
class TofuSoupProvider:
cache_dir: str = "/tmp/tofusoup-cache"
cache_ttl_hours: int = 24
Data Sources¶
Data sources are organized by capability:
Registry Data Sources (6)¶
Query provider and module information from Terraform/OpenTofu registries: 1. provider_info - Provider metadata and latest version 2. provider_versions - All versions with platform support 3. module_info - Module metadata and details 4. module_versions - All module versions 5. module_search - Search modules by query 6. registry_search - Unified provider and module search
State Inspection Data Sources (3)¶
Read and analyze Terraform state files: 1. state_info - State metadata and statistics 2. state_resources - Resource listing and filtering 3. state_outputs - Output value extraction
Async Architecture¶
All registry operations are fully async using Python's asyncio:
async def read(self, config: ProviderInfoConfig) -> ProviderInfoData:
async with TerraformRegistry() as registry:
details = await registry.get_provider_details(
config.namespace,
config.name
)
return ProviderInfoData(...)
Benefits: - Non-blocking I/O for registry queries - Concurrent request handling - Improved performance for batch operations
Build Process¶
FlavorPack Packaging¶
- Entry Point:
pyvider.cli:main - Binary Generation: Cross-platform executables
- Output:
dist/terraform-provider-tofusoup - Platforms: darwin_arm64, linux_amd64, linux_arm64, windows_amd64
Local Installation¶
Provider installs to:
~/.terraform.d/plugins/local/providers/tofusoup/{version}/{platform}/
โโโ terraform-provider-tofusoup
Configuration Files¶
- pyproject.toml: Python dependencies, tool settings
- soup.toml: Pyvider configuration, FlavorPack settings, wrknv tasks
- mkdocs.yml: Documentation site configuration
Documentation Generation¶
Plating generates documentation from: 1. Docstrings: Component docstrings with examples 2. Schemas: Automatically extracted from Pyvider schemas 3. Examples: Working Terraform configurations
Output: - Individual data source pages - Provider configuration reference - Guides and examples
Testing Strategy¶
Test Categories¶
- Unit Tests: Individual component testing
- Integration Tests: End-to-end data source operations
- Async Tests: Async operation verification
Test Structure¶
tests/
โโโ data_sources/
โโโ test_provider_info.py
โโโ test_provider_versions.py
โโโ test_module_info.py
โโโ test_module_versions.py
โโโ test_module_search.py
โโโ test_registry_search.py
โโโ test_state_info.py
โโโ test_state_resources.py
โโโ test_state_outputs.py
Coverage: 280/280 tests passing
Dependencies¶
Core Dependencies¶
- pyvider - Provider framework
- tofusoup - Registry client and state utilities
- provide-foundation - Logging and telemetry
Build Dependencies¶
- flavorpack - Binary packaging
- plating - Documentation generation
Development Dependencies¶
- pytest + pytest-asyncio - Testing
- ruff - Linting and formatting
- mypy - Type checking
Platform Support¶
- Python: 3.11 or higher
- Terraform/OpenTofu: 1.6 or higher
- Platforms:
- macOS (arm64, amd64)
- Linux (amd64, arm64)
- Windows (amd64)
Performance Characteristics¶
Registry Queries¶
- Caching: Configurable TTL (default: 24 hours)
- Async: Non-blocking concurrent requests
- Error Handling: Retry logic with exponential backoff
State Inspection¶
- Read-Only: No state modifications
- Streaming: Large state files processed efficiently
- Memory: Minimal memory footprint
Potential Enhancements¶
- Integration Testing: Full end-to-end test suite
- Remote State: Backend support for S3, GCS, Azure
- Enhanced Caching: Distributed cache support
- Additional Data Sources: Dependencies, platform details
- CI/CD: GitHub Actions pipeline
Design Principles¶
- Read-Only Operations: Never modify state files
- Async-First: All I/O operations are async
- Type Safety: Full mypy type checking
- Comprehensive Testing: 100% critical path coverage
- Documentation: Auto-generated from code
- Cross-Platform: Native binaries for all platforms