Skip to content

factory

πŸ€– AI-Generated Content

This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.

pyvider.schema.factory

Classes

Functions

a_null

a_null(
    schema_builder: PvsAttribute | PvsSchema,
) -> CtyValue

Creates a null CtyValue for a given schema attribute or object.

Source code in pyvider/schema/factory.py
def a_null(schema_builder: PvsAttribute | PvsSchema) -> CtyValue:
    """Creates a null CtyValue for a given schema attribute or object."""
    target_type: CtyType | None = None
    if isinstance(schema_builder, PvsAttribute):
        target_type = schema_builder.type
    elif isinstance(schema_builder, PvsSchema):
        target_type = schema_builder.block.to_cty_type()

    if target_type is None:
        raise TypeError("a_null() expects a schema builder instance like a_str() or s_resource()")
    return CtyValue.null(target_type)

a_unknown

a_unknown(
    schema_builder: PvsAttribute | PvsSchema,
) -> CtyValue

Creates an unknown CtyValue for a given schema attribute or object.

Source code in pyvider/schema/factory.py
def a_unknown(schema_builder: PvsAttribute | PvsSchema) -> CtyValue:
    """Creates an unknown CtyValue for a given schema attribute or object."""
    target_type: CtyType | None = None
    if isinstance(schema_builder, PvsAttribute):
        target_type = schema_builder.type
    elif isinstance(schema_builder, PvsSchema):
        target_type = schema_builder.block.to_cty_type()

    if target_type is None:
        raise TypeError("a_unknown() expects a schema builder instance like a_str() or s_resource()")
    return CtyValue.unknown(target_type)

s_function

s_function(
    parameters: list[PvsAttribute] | None = None,
    return_type: PvsAttribute | None = None,
    variadic_parameter: PvsAttribute | None = None,
) -> PvsSchema

Create a schema for a Terraform function.

Parameters:

Name Type Description Default
parameters list[PvsAttribute] | None

List of function parameters (created with a_str(), a_num(), etc.)

None
return_type PvsAttribute | None

The function's return type (created with a_str(), a_num(), etc.)

None
variadic_parameter PvsAttribute | None

Optional variadic parameter for functions that accept variable arguments

None

Returns:

Name Type Description
PvsSchema PvsSchema

A schema representing the function signature

Example

schema = s_function( ... parameters=[ ... a_str(description="Input string"), ... a_num(description="Multiplier"), ... ], ... return_type=a_str(description="Processed result"), ... )

Source code in pyvider/schema/factory.py
def s_function(
    parameters: list[PvsAttribute] | None = None,
    return_type: PvsAttribute | None = None,
    variadic_parameter: PvsAttribute | None = None,
) -> PvsSchema:
    """
    Create a schema for a Terraform function.

    Args:
        parameters: List of function parameters (created with a_str(), a_num(), etc.)
        return_type: The function's return type (created with a_str(), a_num(), etc.)
        variadic_parameter: Optional variadic parameter for functions that accept variable arguments

    Returns:
        PvsSchema: A schema representing the function signature

    Example:
        >>> schema = s_function(
        ...     parameters=[
        ...         a_str(description="Input string"),
        ...         a_num(description="Multiplier"),
        ...     ],
        ...     return_type=a_str(description="Processed result"),
        ... )
    """
    # Build attributes dict to store function metadata
    # We use a special structure where parameters are stored as numbered attributes
    attributes: dict[str, PvsAttribute] = {}

    # Store parameters as param_0, param_1, etc.
    if parameters:
        for idx, param in enumerate(parameters):
            attributes[f"param_{idx}"] = param

    # Store return type as special attribute
    if return_type:
        attributes["return_type"] = return_type

    # Store variadic parameter if provided
    if variadic_parameter:
        attributes["variadic_param"] = variadic_parameter

    return _create_schema(1, attributes=attributes, block_types=None)