pulumi

Way in Pulumi to run a function only when pulumi up deploys resources and not during a preview?


Is there any way in a Pulumi project to run a function only when pulumi is actually deploying the resources to the cloud during the pulumi up after the user accepts to deploy?

I have an scenario were I need to run a custom code for aws like this:

myAwsModule.putResourcePolicy({policyName: "AWSLogDeliveryWrite20150319",/*...*/});

I don't think I can make this change using @pulumi/aws because it is a special ResourcePolicy that aws sometimes automatically generates but sometimes it could not exist yet, and pulumi seems to require to have a deterministic knowledge of the resource existing or not.

I want to avoid the code from above example to run during a pulumi preview or during a pulumi up if the user doesn't accept to actually run it, so I was hoping there would be something like this:

if (!pulumi.isPreview) {
  myAwsModule.putResourcePolicy({policyName: "AWSLogDeliveryWrite20150319",/*...*/});
}

Is there something like that or any other way to achieve the same result?


Solution

  • pulumi.runtime.isDryRun

    https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/runtime/#isDryRun

    Different casing for all SDKs, but it's available across all