[GH-ISSUE #31] [REFACTOR] Better datastructure for tfdata #15

Closed
opened 2026-05-06 12:36:12 +02:00 by BreizhHardware · 1 comment

Originally created by @alexisdrakopoulos on GitHub (May 29, 2023).
Original GitHub issue: https://github.com/patrickchugh/terravision/issues/31

tfdata is used throughout the code base and contains an undocumented number of keys and untyped values. This makes it quite complex to test and understand.

I would like a dataclass or pydantic model to handle this, here is my proposed model from some early tests:

from pydantic import BaseModel
from tempfile import TemporaryDirectory
from typing import Union, Any

class TFData(BaseModel):
    """
    Container for the Terraform data. All types are optional.
    """
    resource_files: dict[str, Union[dict, list[dict]]] = {}
    data_files: dict[str, list[dict[str, dict]]] = {}
    output_files: dict[str, list[dict[str, dict]]] = {}
    module_files: dict[str, list[dict[str, dict]]] = {}
    variable_files: dict[str, list[dict[str, dict]]] = {}
    locals_files: dict[str, dict] = {}

    varfile_list: tuple = tuple()
    module_source_dict: dict[str, str] = {}
    tempdir: TemporaryDirectory = None
    annotations: dict[str, Any] = {}
    variable_list: dict[str, Any] = {}
    variable_map: dict[str, dict[str, Any]] = {}
    meta_data: dict[str, Any] = {}
    node_list: list[str] = []
    hidden: list[Any] = []
    graphdict: dict[str, list[str]] = {}

    def __getitem__(self, item):
        return getattr(self, item)
    
    def __setitem__(self, key, item):
        setattr(self, key, item)
    
    class Config:
        arbitrary_types_allowed = True

Note:

  • we implement getitem and setitem to allow the current dictionary style interface.
  • I'm unsure of the types of many of these and just looked at an existing tfdata from the examples
Originally created by @alexisdrakopoulos on GitHub (May 29, 2023). Original GitHub issue: https://github.com/patrickchugh/terravision/issues/31 tfdata is used throughout the code base and contains an undocumented number of keys and untyped values. This makes it quite complex to test and understand. I would like a dataclass or pydantic model to handle this, here is my proposed model from some early tests: ```python from pydantic import BaseModel from tempfile import TemporaryDirectory from typing import Union, Any class TFData(BaseModel): """ Container for the Terraform data. All types are optional. """ resource_files: dict[str, Union[dict, list[dict]]] = {} data_files: dict[str, list[dict[str, dict]]] = {} output_files: dict[str, list[dict[str, dict]]] = {} module_files: dict[str, list[dict[str, dict]]] = {} variable_files: dict[str, list[dict[str, dict]]] = {} locals_files: dict[str, dict] = {} varfile_list: tuple = tuple() module_source_dict: dict[str, str] = {} tempdir: TemporaryDirectory = None annotations: dict[str, Any] = {} variable_list: dict[str, Any] = {} variable_map: dict[str, dict[str, Any]] = {} meta_data: dict[str, Any] = {} node_list: list[str] = [] hidden: list[Any] = [] graphdict: dict[str, list[str]] = {} def __getitem__(self, item): return getattr(self, item) def __setitem__(self, key, item): setattr(self, key, item) class Config: arbitrary_types_allowed = True ``` Note: - we implement __getitem__ and __setitem__ to allow the current dictionary style interface. - I'm unsure of the types of many of these and just looked at an existing tfdata from the examples
BreizhHardware 2026-05-06 12:36:12 +02:00
Author
Owner

@patrickchugh commented on GitHub (Dec 16, 2025):

Unnecessary complexity and requires too many code changes for little benefit.

<!-- gh-comment-id:3662744377 --> @patrickchugh commented on GitHub (Dec 16, 2025): Unnecessary complexity and requires too many code changes for little benefit.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/terravision#15
No description provided.