millions-pharmacist-626
04/05/2023, 10:57 AMglue.JobArgs()
to define args of a glue.Job()
resource, instead of just passing them directly to glue.Job
? Is there an advantage with this approach over the other?
Reference docs: https://www.pulumi.com/registry/packages/aws/api-docs/glue/job/#inputsgreat-sunset-355
04/05/2023, 11:12 AMargs
passed to glue.Job(args)
This is a common pattern which helps with testing, etc...millions-pharmacist-626
04/05/2023, 11:14 AMgreat-sunset-355
04/05/2023, 11:21 AMmillions-pharmacist-626
04/05/2023, 11:26 AMgreat-sunset-355
04/05/2023, 11:40 AMinterface
as a typed Dict
or a dataclass
. Instantiating a class in python is not as elegant as creating an object in JS/TS. Object in JS/TS is more close to Dict in python however, pulumi does not support type discs (yet, there's an issue about it's support).
Also note, pulumi has to bend some good practices to make things work, so it may not be obvious why they do things the way they do.
I'd suggest reading a smaller project like this https://github.com/pulumi/pulumi-synced-folder/blob/main/provider/cmd/pulumi-resource-synced-folder/s3-bucket-folder.ts#L29
to learn more about how to write pulumi.millions-pharmacist-626
04/05/2023, 11:47 AMlimited-rainbow-51650
04/05/2023, 11:55 AMargs
, followed by opts
, is that we can make this 3 piece setup (name
, args
, opts
) to create a resource consistent over the different programming languages. You will see this pattern consistently applied over our supported programming languages and providers.millions-pharmacist-626
04/05/2023, 11:56 AMgreat-sunset-355
04/05/2023, 11:56 AMJob("name", prop=val, prop2=val)
or Job("name", args=JobArgs(prop=val, prop2=val), opts=ResourceOptions())
- In the beginning I noticed that IDEs did not really work well with the formerlimited-rainbow-51650
04/05/2023, 11:57 AMkwargs
version of the constructor. Given we flatten this via kwargs
, it is no longer possible to perform a certain level of type checking, delaying some validation until runtime. It is up to you what you use, but we propose to use the less Pythonic 3-piece constructor if you want a faster development roundtrip.millions-pharmacist-626
04/05/2023, 12:01 PMlimited-rainbow-51650
04/05/2023, 12:04 PMa certain level of type checking
, while I should have said: a certain level of input validation
. The kwargs
version of the constructor doesn't support validating if all required properties are passed, let alone nested properties.millions-pharmacist-626
04/05/2023, 12:07 PM