Skip to content

PulumiStack

laktory.models.PulumiStack ¤

Bases: BaseModel

A Pulumi stack is pulumi-specific flavor of the laktory.models.Stack. It re-structure the attributes to be aligned with a Pulumi.yaml file.

It is generally not instantiated directly, but rather created using laktory.models.Stack.to_pulumi().

References
METHOD DESCRIPTION
model_dump

Serialize model to match the structure of a Pulumi.yaml file.

write

Write Pulumi.yaml configuration file

preview

Runs pulumi preview

up

Runs pulumi up

destroy

Runs pulumi destroy

Functions¤

model_dump ¤

model_dump(*args, **kwargs)

Serialize model to match the structure of a Pulumi.yaml file.

Source code in laktory/models/stacks/pulumistack.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def model_dump(self, *args, **kwargs) -> dict[str, Any]:
    """Serialize model to match the structure of a Pulumi.yaml file."""
    self._configure_serializer(camel=True)
    kwargs["exclude_none"] = kwargs.get("exclude_none", True)
    d = super().model_dump(*args, **kwargs)

    # Special treatment of resources
    for r in self.resources.values():
        d["resources"][r.resource_name] = {
            "type": r.pulumi_resource_type,
            "properties": r.pulumi_properties,
            "options": r.options.model_dump(
                include=r.options.pulumi_options, exclude_unset=True
            ),
        }

        lookup = r.lookup_existing
        if lookup is not None:
            d["resources"][r.resource_name]["get"] = lookup.pulumi_dump()
            del d["resources"][r.resource_name]["properties"]

    self._configure_serializer(camel=False)

    # Pulumi YAML requires the keyword "resources." to be removed
    pattern = r"\$\{resources\.(.*?)\}"
    self.variables[pattern] = r"${\1}"
    d = self.inject_vars_into_dump(d)
    del self.variables[pattern]

    return d

write ¤

write()

Write Pulumi.yaml configuration file

RETURNS DESCRIPTION
str

Filepath of the configuration file

Source code in laktory/models/stacks/pulumistack.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def write(self) -> str:
    """
    Write Pulumi.yaml configuration file

    Returns
    -------
    :
        Filepath of the configuration file
    """
    filepath = os.path.join(CACHE_ROOT, "Pulumi.yaml")

    if not os.path.exists(CACHE_ROOT):
        os.makedirs(CACHE_ROOT)

    with open(filepath, "w") as fp:
        yaml.dump(self.model_dump(), fp)

    return filepath

preview ¤

preview(stack=None, flags=None)

Runs pulumi preview

PARAMETER DESCRIPTION
stack

Name of the stack to use

TYPE: str DEFAULT: None

flags

List of flags / options for pulumi preview

TYPE: list[str] DEFAULT: None

Source code in laktory/models/stacks/pulumistack.py
120
121
122
123
124
125
126
127
128
129
130
131
def preview(self, stack: str = None, flags: list[str] = None) -> None:
    """
    Runs `pulumi preview`

    Parameters
    ----------
    stack:
        Name of the stack to use
    flags:
        List of flags / options for pulumi preview
    """
    self._call("preview", stack=stack, flags=flags)

up ¤

up(stack=None, flags=None)

Runs pulumi up

PARAMETER DESCRIPTION
stack

Name of the stack to use

TYPE: str DEFAULT: None

flags

List of flags / options for pulumi up

TYPE: list[str] DEFAULT: None

Source code in laktory/models/stacks/pulumistack.py
133
134
135
136
137
138
139
140
141
142
143
144
def up(self, stack: str = None, flags: list[str] = None):
    """
    Runs `pulumi up`

    Parameters
    ----------
    stack:
        Name of the stack to use
    flags:
        List of flags / options for pulumi up
    """
    self._call("up", stack=stack, flags=flags)

destroy ¤

destroy(stack=None, flags=None)

Runs pulumi destroy

PARAMETER DESCRIPTION
stack

Name of the stack to use

TYPE: str DEFAULT: None

flags

List of flags / options for pulumi up

TYPE: list[str] DEFAULT: None

Source code in laktory/models/stacks/pulumistack.py
146
147
148
149
150
151
152
153
154
155
156
157
def destroy(self, stack: str = None, flags: list[str] = None):
    """
    Runs `pulumi destroy`

    Parameters
    ----------
    stack:
        Name of the stack to use
    flags:
        List of flags / options for pulumi up
    """
    self._call("destroy", stack=stack, flags=flags)