glamorous-forest-5773
01/27/2022, 9:20 AMpulumi.input_type
decorator to define internal datatypes.
I'm trying to use Pydantic + pulumi.input_type decorator to create schemas with validation + the ability to resolve nested Output attributes. But it looks like, the decorator is tampering the attributes which results in some weird behavior for pydantic models.great-queen-39697
01/27/2022, 3:48 PMgreat-sunset-355
01/31/2022, 10:16 AMfrom typing import Sequence, TypeVar, Union
from pydantic import BaseModel
import pulumi
T = TypeVar("T")
PulumiSequenceInputLike = Union[Sequence[T], pulumi.Output[T]]
PulumiInputLike = Union[T, pulumi.Output[T]]
class AutoScalingArgs(BaseModel):
"""Fargate autoscaling arguments."""
memory_target_value: PulumiInputLike[int] = 60
"""Scale up when memory usage exceeds the value [%]."""
cpu_target_value: PulumiInputLike[int] = 60
"""Scale up when CPU usage exceeds the value [%]."""
max_tasks: PulumiInputLike[int] = 4
min_tasks: PulumiInputLike[int] = 1
desired_count: PulumiInputLike[int] = 1
class Config:
arbitrary_types_allowed = True
glamorous-forest-5773
02/22/2022, 11:41 AMpulumi.input_type
decorator is messing up the pydantic attributesgreat-sunset-355
02/22/2022, 11:45 AMInput
type, you need to use Output
as a typeglamorous-forest-5773
02/22/2022, 11:46 AM@pulumi.runtime.test
def test_person_with_default():
from pydantic import BaseModel
from typing import TypeVar, Union, Optional
T = TypeVar("T")
Input = Union[T, pulumi.Output[T]]
class PulumiBaseModel(BaseModel):
class Config:
arbitrary_types_allowed = True
@pulumi.input_type
class Person(PulumiBaseModel):
name: Optional[Input[str]] = "John Doe"
a = Person()
def check(a):
assert a.name == "John Doe"
return pulumi.Output.from_input(a).apply(check)
test_person_with_default Failed: [undefined]TypeError: __create_fn__.<locals>.__init__() missing 1 required keyword-only argument: 'name'
great-sunset-355
02/22/2022, 2:21 PMglamorous-forest-5773
02/23/2022, 7:14 AM