Hey folks, is there now a recommended way to itera...
# general
s
Hey folks, is there now a recommended way to iterate over an
Output<List<T>>
other than
apply(l => l.map(...))
? I've been looking at (1), which suggests it's best not to create resources in an
.apply
, and (2) which suggests that sometimes this is the only way to do it. 1. https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply 2. https://github.com/pulumi/pulumi/issues/5392
e
1 is because these won't always show up at preview time so your actual update may differ from preview. 2 means that sometimes you still need to do this 😞 I do have some ideas around making things better here, but for now apply is the way to handle this.
s
@echoing-dinner-19531 Makes sense to me. I tried a couple of different patterns, but in cases where you don't know the length of the array up-front it seems that
apply
is still necessary. Ended up refactoring to make it static in the case I was looking at. Care to share any of your ideas? ;)
e
Two ideas. 1 is adding a
mustApply
function so we can at least error out that you have resources trying to be created in preview, but
--targets
would allow you to still run an
up
without that error blocking the whole operation (this is exactly the same behaviour as TF) 2 is adding a applyMap function that would let the engine understand iteration, so it wouldn't be able to say how many resources we're going to be made but it could say 0 or more.