https://pulumi.com logo
Title
l

little-journalist-4778

08/09/2021, 11:26 AM
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:
@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

great-sunset-355

08/09/2021, 11:49 AM
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

little-journalist-4778

08/09/2021, 11:58 AM
yes but as you can see i need to pass lists of custom input types
g

great-sunset-355

08/09/2021, 12:33 PM
which list?
groups
? -> it's actually not a list it is an
Output[Sequence[str]]
it's 1 item
Outputs are helluva confusing
l

little-journalist-4778

08/09/2021, 12:38 PM
@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
@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

great-sunset-355

08/09/2021, 12:45 PM
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

little-journalist-4778

08/09/2021, 12:47 PM
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

great-sunset-355

08/09/2021, 12:51 PM
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

little-journalist-4778

08/09/2021, 12:51 PM
yep but I just did a test and this looks like a bug
g

great-sunset-355

08/09/2021, 12:53 PM
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

little-journalist-4778

08/09/2021, 12:53 PM
this works:
@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:
@pulumi.input_type
class ClusterArgs:
    k8s_version: Optional[pulumi.Input[str]] = pulumi.property("k8s_version", default="1.21")
g

great-sunset-355

08/09/2021, 12:58 PM
are you able to share the whole source? I'd be very interested to learn from it
b

billowy-army-68599

08/09/2021, 4:15 PM
@little-journalist-4778 just catching up here - you're trying to create a multi language component, right?
l

little-journalist-4778

08/09/2021, 4:15 PM
nope
b

billowy-army-68599

08/09/2021, 4:15 PM
just a standard component?
l

little-journalist-4778

08/09/2021, 4:15 PM
yes
b

billowy-army-68599

08/09/2021, 4:17 PM
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

little-journalist-4778

08/09/2021, 4:18 PM
ok but i think the decorator
pulumi.input_type
is necessary
b

billowy-army-68599

08/09/2021, 4:19 PM
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

little-journalist-4778

08/09/2021, 4:19 PM
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