Skip to content

BaseResource

laktory.models.resources.BaseResource ¤

Parent class for all Laktory models deployable as one or multiple cloud core resources. This BaseResource class is derived from pydantic.BaseModel.

PARAMETER DESCRIPTION
lookup_existing

Import a pre-existing resource instead of creating a new one. The resource becomes available for cross-referencing (${resources.<name>.<property>}) and child resource deployment (grants, schemas, etc.); its own field values are not written to the existing resource.

TYPE: ResourceLookup | VariableType DEFAULT: None

resource_options

Deployed resource options (name, provider, enabled flag, dependencies, etc.).

TYPE: ResourceOptions | VariableType DEFAULT: ResourceOptions(variables={}, name=None, is_enabled=True, depends_on=[], provider=None, ignore_changes=None, import_=None, moved_from=None)

METHOD DESCRIPTION
lookup

Create an instance that references an existing resource without managing it.

resource_options_compat

Backward compatibility for options field.

ATTRIBUTE DESCRIPTION
core_resources

List of core resources to be deployed with this laktory model:

resource_key

Resource key used to build default resource name. Equivalent to

TYPE: str

resource_name

Logical name of the resource within the stack — auto-generated as

TYPE: str

resource_type_id

Resource type id used to build default resource name. Equivalent to

TYPE: str

self_as_core_resources

Flag set to True if self must be included in core resources

core_resources property ¤

List of core resources to be deployed with this laktory model: - class instance (self)

resource_key property ¤

Resource key used to build default resource name. Equivalent to name properties if available. Otherwise, empty string.

resource_name property ¤

Logical name of the resource within the stack — auto-generated as {resource_type_id}-{resource_safe_key} unless overridden via resource_options.name. Used as the IaC state address and as the key for ${resources.<name>.<property>} cross-references.

resource_type_id property ¤

Resource type id used to build default resource name. Equivalent to class name converted to kebab case. e.g.: SecretScope -> secret-scope

self_as_core_resources property ¤

Flag set to True if self must be included in core resources

lookup(lookup_existing, **kwargs) classmethod ¤

Create an instance that references an existing resource without managing it.

Required fields are filled with placeholder values so Pydantic validation passes — only lookup_existing is used at deploy time. Prefer this over passing lookup_existing directly to the constructor to make the intent explicit.

Source code in laktory/models/resources/baseresource.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
@classmethod
def lookup(
    cls, lookup_existing: "ResourceLookup | dict", **kwargs
) -> "BaseResource":
    """
    Create an instance that references an existing resource without managing it.

    Required fields are filled with placeholder values so Pydantic validation
    passes — only `lookup_existing` is used at deploy time. Prefer this over
    passing `lookup_existing` directly to the constructor to make the intent
    explicit.
    """
    data = {"lookup_existing": lookup_existing, **kwargs}
    return cls.model_validate(cls._apply_lookup_placeholders(data))

resource_options_compat(data) classmethod ¤

Backward compatibility for options field.

Source code in laktory/models/resources/baseresource.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@model_validator(mode="before")
@classmethod
def resource_options_compat(cls, data: Any) -> Any:
    """Backward compatibility for `options` field."""
    if not isinstance(data, dict):
        return data

    # options → resource_options (only when no native Terraform "options" field exists)
    if "options" in data and "resource_options" not in data:
        if "options" not in cls.model_fields:
            warnings.warn(
                "Field `options` is deprecated and will be removed in the next major version. "
                "Use `resource_options` instead.",
                DeprecationWarning,
                stacklevel=2,
            )
            data["resource_options"] = data.pop("options")

    return data

laktory.models.resources.baseresource.ResourceOptions ¤

Bases: BaseModel

Resource options for deployment.

PARAMETER DESCRIPTION
depends_on

Explicit list of resource dependencies.

TYPE: list[str | VariableType] | VariableType DEFAULT: []

ignore_changes

Declare that changes to certain properties should be ignored during a diff.

TYPE: list[str | VariableType] | VariableType DEFAULT: None

import_

Bring an existing cloud resource into Laktory management.

TYPE: str | VariableType DEFAULT: None

is_enabled

If False, resource is not passed to the IaC backend and is not deployed. May be used for deploying resources to specific stack environments only or for disabling resources when debugging.

TYPE: bool | VariableType DEFAULT: True

moved_from

Declare that a resource was moved from another address.

TYPE: str | VariableType DEFAULT: None

name

Logical name of the resource within the stack. Used by the IaC backend to track the resource across deployments, and as the key for cross-referencing this resource from other resources or YAML configs via ${resources.<name>.<property>} (e.g., ${resources.catalog-dev.id}).

If None, the name is auto-generated as {type_id}-{resource_key} where: - type_id is the class name in kebab-case (e.g., Catalogcatalog, SecretScopesecret-scope) - resource_key is the resource name property with special characters replaced by -

Examples of auto-generated names: - Catalog(name="dev")catalog-dev - Schema(name="finance", catalog_name="dev")schema-dev-finance - Table(name="slv_stock_prices", catalog_name="dev", schema_name="finance")table-dev-finance-slv_stock_prices

Set this explicitly to pin the resource address and prevent destroy-and-recreate when the resource name property changes. The value must start with a letter and contain only letters, digits, hyphens, underscores, or ${vars.*} placeholders.

TYPE: str | VariableType DEFAULT: None

provider

Explicit declaration of resource provider.

TYPE: str | VariableType DEFAULT: None


laktory.models.resources.baseresource.ResourceLookup ¤

Bases: BaseModel