Pulumi中的方法,在pulumi up 部署资源时运行函数,而不是在预览期间运行?

huangapple go评论147阅读模式
英文:

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

问题

Pulumi项目中,是否有一种方法可以在用户接受部署后,仅在pulumi up实际部署资源到云上时运行函数?

我有一个场景,我需要像这样为AWS运行自定义代码:

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

我认为我不能使用@pulumi/aws来进行此更改,因为它是AWS有时会自动生成但有时可能尚不存在的特殊ResourcePolicy,并且Pulumi似乎要求对资源的存在或不存在具有确定性知识。

我希望避免在pulumi preview期间或在用户不接受实际运行它的情况下,在pulumi up期间运行上述示例中的代码,所以我希望有类似这样的东西:

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

是否有类似的东西或实现相同结果的其他方法?

英文:

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?

答案1

得分: 1

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

英文:

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

huangapple
  • 本文由 发表于 2023年5月25日 17:55:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定