This message was deleted.
s
This message was deleted.
b
Not with a "standard" Pulumi program, but you can using our automation SDK
👍🏼 1
h
Thanks for the quick response, @brave-planet-10645. Do you have any link pointing to an example maybe?
b
And if you still hit on the 712 promises still active after you go for automation - perhaps you can have a look for similarities with this: https://github.com/pulumi/pulumi/issues/6633
👍🏼 1
b
@hallowed-camera-52062 we have a whole load of examples here: https://github.com/pulumi/automation-api-examples
😍 1
h
Thanks a lot, people! 🙏🏼
d
Instead of exitting a Pulumi program on a condition, you can lazily register your Pulumi resources by wrapping them into a JS function that evaluates on a condition, and optionally returns Outputs:
Copy code
const lazyRunner = (resources: ResourceDefinition[]): ResourceOutputs => {
    return resources.map((resource) => {
        const getConventionName: ConventionNameGetter = useNamingConvention(
            resource.name,
            resource.environment
        )
        return provisionResource(resource, getConventionName)
    })
}

const environmentName: string = pulumi.getStack().toLowerCase()
// Filter the resources that belong to the current environment
const resources: ResourceDefinition[] = resourcesDefinitions.filter(
  (r: ResourceDefinition) => r.environment === environmentName
)

if (resources.length === 0) {
  console.log(
    `There are no resources to be deployed onto the current environment ('${environmentName}'). Skipping...`
  )
}

export const resourceOutputs: ResourceOutputs = (resources.length === 0) ? null : lazyRunner(resources)