Skip to content

[Subissue 6/7] Template System Integration (Optional) #40

Closed

Description

@josecelano

Parent Epic: #34 - Implement Create Environment Command
Status: OPTIONAL ENHANCEMENT
Estimated Time: 2-3 hours

⚠️ Note: This is an optional enhancement that can be deferred. It is not required for the MVP functionality of the create command.

Overview

Implement the template system for configuration file generation in the infrastructure layer. This system provides embedded JSON configuration templates that can be generated on-demand, supporting the --generate-template functionality with proper error handling and validation.

Goals

  • Extend existing TemplateManager from src/domain/template/embedded.rs for configuration templates
    • Use existing template infrastructure - no duplication needed
    • Add configuration template types to existing embedded template system
    • Leverage existing rust-embed pattern in templates/ directory structure
    • Use existing TemplateManagerError for error handling
  • Add configuration templates to existing template structure
    • Add to existing templates/ directory following existing patterns
    • Use existing Tera variable syntax: {{ variable_name }} (not { { variable_name } })
    • Follow existing template embedding and extraction patterns
  • Add --generate-template functionality using existing template infrastructure
  • Add unit tests that integrate with existing template system

Architecture Requirements

DDD Layer: Infrastructure Layer (src/infrastructure/templates/)
Pattern: Template Provider + Embedded Resources + File Operations
Dependencies: None (infrastructure concern)

Template Example

{
  "environment": {
    "name": "{{ environment_name }}"
  },
  "ssh_credentials": {
    "private_key_path": "{{ ssh_private_key_path }}",
    "public_key_path": "{{ ssh_public_key_path }}",
    "username": "{{ ssh_username }}",
    "port": {{ ssh_port }}
  }
}

Acceptance Criteria

  • Template provider extends existing TemplateManager infrastructure
  • Templates use correct Tera variable syntax: {{ variable }}
  • Templates generate valid JSON files
  • Error handling follows tiered help system pattern
  • Unit tests verify template generation works correctly
  • Integration tests verify file system operations
  • Templates are embedded in binary using existing rust-embed pattern

Implementation Notes

  • Reuse existing TemplateManager from src/domain/template/embedded.rs
  • Add configuration templates to templates/ directory structure
  • Use existing error types from template system
  • Follow patterns established in OpenTofu/Ansible template management

For detailed specification, see: docs/issues/epic-create-environment-command-subissue-6-template-system-integration.md

Activity

  1. added
    enhancement
    on Oct 25, 2025
  2. added a commit that references this issue on Oct 25, 2025
  3. added 2 commits that reference this issue on Oct 26, 2025
  4. added a commit that references this issue on Oct 27, 2025
  5. josecelano commented on Oct 27, 2025

    @josecelano
    MemberAuthor

    Approach Revision: Struct-Based Template Generation

    After starting implementation, I've revised the approach for this issue to use struct-based JSON generation instead of embedded templates.

    Why the Change?

    The original specification suggested using the existing TemplateManager system, but this led to confusion:

    1. TemplateManager is for infrastructure templates (Ansible, OpenTofu files) used during deployment
    2. This feature generates user configuration templates that users manually edit
    3. The template structure exactly matches EnvironmentCreationConfig struct

    Creating a separate template file would duplicate the struct definition and require manual synchronization.

    New Approach

    Generate the template directly from the Rust struct:

    impl EnvironmentCreationConfig {
        pub fn template() -> Self {
            // Returns struct with placeholders for required fields
            // and defaults for optional fields
        }
        
        pub async fn generate_template_file(path: &Path) -> Result<...> {
            // Serializes template struct to JSON and writes to file
        }
    }

    Benefits:

    • Type-safe and compiler-verified
    • Zero duplication (struct IS the template)
    • Auto-synced with struct changes
    • Guaranteed valid JSON

    Updated Documentation

    The v2 spec includes:

    • Complete implementation guidance
    • Comprehensive code examples
    • Test cases and error handling
    • Explanation of why this approach is superior

    Impact

    This change makes the codebase more maintainable and eliminates an entire category of potential sync issues between code and templates.

  6. added a commit that references this issue on Oct 27, 2025
  7. added a commit that references this issue on Oct 27, 2025
  8. added 2 commits that reference this issue on Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementoptional

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions