Hi I'm creating a custom ComponentResource in pyth...
# python
l
Hi I'm creating a custom ComponentResource in python, and I'm not understanding if I'm supposed to declare my custom arg class like this:
Copy code
@pulumi.input_type
class RoleMappingArgs:
    groups: pulumi.Input[Sequence[pulumi.Input[str]]] = pulumi.property("groups")
    role_arn: pulumi.Input[str] = pulumi.property("role_arn")
    username: pulumi.Input[str] = pulumi.property("username")
Or is this something I should use only for cross language components? I can just declare nested args classes and the Outputs will be respected correctly?
g
I do not think this will work for ComponentResource. I only use attributes and arguments supplied to
__init__
eg:
def __init__(self, role_arn: pulumi.Output[str])
there is some async magic behind outputs and inputs I think it may have been easier if entire pulumi decided to support only async
l
yes but as you can see i need to pass lists of custom input types
g
which list?
groups
? -> it's actually not a list it is an
Output[Sequence[str]]
it's 1 item
Outputs are helluva confusing
l
@great-sunset-355 sorry I'll try to explain better, I've a CustomResource called
Cluster
I've made this class
ClusterArgs
that has an attribute
role_mappings
Copy code
@pulumi.input_type
class ClusterArgs:
    role_mappings: Optional[pulumi.Input[Sequence[pulumi.InputType['RoleMappingArgs']]]] = pulumi.property("role_mappings", default=None)
I've followed exactly how
pulumi_eks
ComponentResource is made
g
yeah, I'd say you are out of luck here, as the issue says they are meant for internal use. I've had a lot of debates about the patterns for component resources and so far this is the best pattern I found out to work. https://github.com/mitodl/ol-infrastructure/blob/main/src/ol_infrastructure/components/aws/database.py mayby @red-match-15116 could add something here
l
It doesn't look like for internal use, this is the code used by the python custom provider boilerplate (this is the code suggested to create new multilanguage stuff) https://github.com/pulumi/pulumi-component-provider-py-boilerplate/blob/master/sdk/python/pulumi_xyz/static_page.py
g
This is a Pulumi native provider, aka you write the code in Go, and it generates Py, JS, TS, .NET - and uses the internal features
l
yep but I just did a test and this looks like a bug
g
I discovered that repo today, when I found out that AWS provider is missing some API calls I'll need a week to play with it, sorry cannot help with that yet
l
this works:
Copy code
@pulumi.input_type
class ClusterArgs:

    def __init__(__self__, *,
                 k8s_version: Optional[pulumi.Input[str]] = "1.21"):
        pulumi.set(__self__, "k8s_version", k8s_version)

    @property
    @pulumi.getter(name="k8s_version")
    def k8s_version(self) -> pulumi.Input[str]:
        return pulumi.get(self, "k8s_version")

    @k8s_version.setter
    def k8s_version(self, value: pulumi.Input[str]):
        pulumi.set(self, "k8s_version", value)
this not:
Copy code
@pulumi.input_type
class ClusterArgs:
    k8s_version: Optional[pulumi.Input[str]] = pulumi.property("k8s_version", default="1.21")
g
are you able to share the whole source? I'd be very interested to learn from it
b
@little-journalist-4778 just catching up here - you're trying to create a multi language component, right?
l
nope
b
just a standard component?
l
yes
b
okay, in that case, input types can easily be either pulumi async types
pulumi.Input
or native types: https://github.com/jaxxstorm/pulumi-nginx-demo/blob/main/nginx-ingress/app.py#L12 if you set them as
pulumi.Input
it'll take either an input, or a string
l
ok but i think the decorator
pulumi.input_type
is necessary
b
yes it might be, for this class of question you might be better off opening an issue - it seems we're missing docs here
sorry for the back and forth
l
I looked inside the Output.from_input function and is able only to deeply unwrap lists, dicts AND INPUT CLASSES https://github.com/pulumi/pulumi/blob/master/sdk/python/lib/pulumi/output.py#L253
If I have nested args classes it will not be able to unwrap them correctly, am I right?
👀 1