when can you use python dicts as inputs into resou...
# python
q
when can you use python dicts as inputs into resources vs the resource args objects e.g.
gcp.compute.FirewallAllowArgs
sometimes the dicts work, sometimes they don't
g
until this is merged https://github.com/pulumi/pulumi/issues/11732 avoid dicts and use
Args
, all other SDKs have the same API
Resource("name", args, opts)
h
Jan, I think that's just the root arguments, which under python can be keyword arguments (which I encourage)
james, all the samples use
*Args
classes for things. I think it's common for them to accept
dict
as well, I don't think it's documented so I wouldn't be surprised if this support is spotty.
g
The unfortunate situation of python SDK are
__init__
overrides with
Copy code
def __init__(__self__,
                 resource_name: str,
                 args: Optional[CertificateArgs] = None,
                 opts: Optional[pulumi.ResourceOptions] = None):
or
Copy code
def __init__(__self__, resource_name: str, *args, **kwargs)
# or

def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 certificate_authority_arn: Optional[pulumi.Input[str]] = None,
                 certificate_body: Optional[pulumi.Input[str]] = None,
                 certificate
This is not the case for other SDKs (TS, Go, .NET) where the structure follows this style with
args
and
opts
Copy code
def __init__(__self__,
                 resource_name: str,
                 args: Optional[CertificateArgs] = None,
                 opts: Optional[pulumi.ResourceOptions] = None):
also, properties have Args eg
CertificateOptionsArgs
-> https://github.com/pulumi/pulumi-aws/blob/master/sdk/python/pulumi_aws/acm/certificate.py#L641C67-L641C89 The reason I recommend this style
Copy code
Certificate("name", CertificateArgs(certificate_options=CertificateOptionsArgs()...), ResourceOptions())
while pretty ugly (IMO) it gives the best intellisense / code completion with typing. This pattern is super elegant in TypeScript where it would look like:
Copy code
new Certificate("name", {certificateOptions:{} }, {parent:""})
And IDE gives you all you need and more when you expand
{}
Hence my high hopes for TypedDict in python because it would make it also quite elegant
h
yes
i know
q
i think i saw some samples using the dicts so had followed them in the past. i noticed pulumi ai generates those as well. after running into instance where they don't work, just started using args.
while pretty ugly (IMO) it gives the best intellisense / code completion with typing.
is that constructor style supported for all resources? can start to use those if the intellisense works