If I have some code written in `my-service.ts`, is...
# general
f
If I have some code written in
my-service.ts
, is there a way to conditionally provision those resources based on a value in the config?
h
You can read the config values with config.get/require and then use an if statement.
If you don't new the resource object it won't be provisioned
f
@helpful-vegetable-35581 Wait what do you mean by new?
h
As in creating a new object like "new aws.rds.Instance(name, args)"
if you don't call that it won't be created by pulumi
f
Hmm that couples my code to the configuration. I suppose I could wrap everything in a function call. It'd also be cool to disable the mutable ctor. i.e. creating a
new
resources returns an object that holds the data needed to do the provisioning. You can then provision the resource by called a method on the object, perhaps
create
, to provision it.
h
Why would you want to create the object if you don't want it provisioned?
f
To remove configuration coupling. It probably makes more sense to just create the object in a function.
h
Right but then just don't call the function if the config says not to
f
Precisely 🙂
h
Right but you don't need a separate create method on the pulumi object for that
f
Yep - the functional approach is better.
👍 1