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

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
44
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
def model_dump(self, *args, **kwargs) -> dict[str, Any]:
    """Serialize model to match the structure of a Pulumi.yaml file."""
    settings.camel_serialization = 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(exclude_none=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"]

    settings.camel_serialization = False

    # Pulumi YAML requires the keyword "resources." to be removed
    pattern = r"\$\{resources\.(.*?)\}"
    self.variables[pattern] = r"${\1}"
    d = self.inject_vars(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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
117
118
119
120
121
122
123
124
125
126
127
128
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
130
131
132
133
134
135
136
137
138
139
140
141
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
143
144
145
146
147
148
149
150
151
152
153
154
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)