Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up custom Flattenable type #86

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions tb_pulumi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from typing import Any


#: Type alias representing valid types to be found among a ThunderbirdPulumiProject's resources
type Flattenable = dict | list | ThunderbirdComponentResource | pulumi.Output | pulumi.Resource


class ThunderbirdPulumiProject:
"""A collection of related Pulumi resources upon which we can take bulk/collective actions. This class enforces some
usage conventions that help keep us organized and consistent.
Expand Down Expand Up @@ -226,12 +230,12 @@ def env_var_is_true(name: str) -> bool:
return env_var_matches(name, ['t', 'true', 'yes'], False)


def flatten(item: dict | list | ThunderbirdComponentResource | pulumi.Output | pulumi.Resource) -> set[pulumi.Resource]:
def flatten(item: Flattenable) -> set[pulumi.Resource]:
"""Recursively traverses a nested collection of Pulumi ``Resource`` s, converting them into a flat set which can be
more easily iterated over.

:param item: Either a Pulumi ``Resource`` object, or some collection thereof. The following types of collections are
supported: ``dict``, ``list``, ``ThunderbirdComponentResource``.
:param item: An item which we intend to flatten. Must be one of the recognized types or collections defined in
the Flattenable type alias.
:type item: dict | list | ThunderbirdComponentResource

:return: A ``set`` of Pulumi ``Resource`` s contained within the collection.
Expand Down
2 changes: 1 addition & 1 deletion tb_pulumi/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
self.supported_resources = []

def __parse_resource_item(
item: list | dict | pulumi.Output | pulumi.Resource | tb_pulumi.ThunderbirdComponentResource,
item: tb_pulumi.Flattenable,
):
"""Not all items in a project's ``resources`` dict are actually Pulumi Resources. Sometimes we build
resources downstream of a Pulumi Output, which makes those resources (as they are known to the project)
Expand Down
Loading