https://pulumi.com logo
f

full-dress-10026

09/24/2018, 7:16 PM
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

helpful-vegetable-35581

09/24/2018, 7:58 PM
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

full-dress-10026

09/24/2018, 8:05 PM
@helpful-vegetable-35581 Wait what do you mean by new?
h

helpful-vegetable-35581

09/24/2018, 8:06 PM
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

full-dress-10026

09/24/2018, 8:14 PM
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

helpful-vegetable-35581

09/24/2018, 8:15 PM
Why would you want to create the object if you don't want it provisioned?
f

full-dress-10026

09/24/2018, 8:16 PM
To remove configuration coupling. It probably makes more sense to just create the object in a function.
h

helpful-vegetable-35581

09/24/2018, 8:17 PM
Right but then just don't call the function if the config says not to
f

full-dress-10026

09/24/2018, 8:17 PM
Precisely 🙂
h

helpful-vegetable-35581

09/24/2018, 8:18 PM
Right but you don't need a separate create method on the pulumi object for that
f

full-dress-10026

09/24/2018, 8:19 PM
Yep - the functional approach is better.
👍 1