What’s the best way to create “presets” in Pulumi ...
# general
r
What’s the best way to create “presets” in Pulumi in Python? For example, I want to create GCP projects with certain defaults (e.g. don’t create the default network), but I still want to allow end users to override those defaults and at the same time dont’ want to maintain a ton of boilerplate if I don’t have to.
b
I think you're looking for a Component Resource: https://www.pulumi.com/docs/intro/concepts/resources/ You can define a class with sane defaults that can be overridden
I have an example somewhere if you need one
s
i’d love to see an example!
r
Ah, that looks like what I’m after. Thanks!
b
you can either import them locally from a file, or publish them to pypi to reuse them
r
@billowy-army-68599 Is there any way to skip defining all the arguments to a particular resource again?
b
what do you mean?
r
Like I want my resource to be a drop-in replacement to the
gcp.organizations.Project
resource. I still want it to accept all the same kwargs, etc.
I just want the ability to change the default values.
b
i'm finding it hard to visualize what you're saying, would you mind sharing some pseudo code?
r
Are you familiar with Ansible at all?
b
not in a long time...
r
Hah
I wish I was less familiar.
I want the ability to specify a set of default arguments to Resources so that I: 1) don’t have to maintain an entire resource definition 2) Don’t clobber user-specified values 3) Can retroactively go back into Pulumi code and insert my custom modules with as little friction as possible.
b
ahh, yeah we don't have that as a built in, you'd have to specify the values for your class and then pass them through to the resources
actually let me get someone smarter to chime in, standby
r
This is where I am almost envious of monkey patching in Ruby. 😄
And then I realize that those are Bad Thoughts.
r
I think you’ll have to create a wrapper function with the defaults defined to do that.
r
Yeah, that’s sort of what I’m trying to avoid.
Because it’s just a ton of Boilerplate.
r
well, don’t know what to tell you friend.
Maybe you’ll come up with a better way and then you can tell us about it
r
Thanks for your help