I keep fighting outputs... given an `Output<Imm...
# dotnet
I keep fighting outputs... given an
(of aws subnet ids fwiw), I need to create a bunch of aws resources for each subnet. Unless I'm missing something, there doesn't seem to be a nice way to enumerate the array outside of apply, since there's no way to get the array length, unless I use
Copy code
var subnetCount = OutputUtilities.GetValueAsync(privateSubnetIds.Apply(ids => ids.Length)).GetAwaiter().GetResult();
for (var i = 0; i < subnetCount; ++i)
    new MountTarget($"{awsEksPrefix}-efs-mount-target-{i + 1}",
        new MountTargetArgs
            FileSystemId = efsfileSystem.Id,
            SecurityGroups = { efsSecurityGroup.Id },
            SubnetId = privateSubnetIds.GetAt(i)
        new CustomResourceOptions { Provider = awsProvider });
Indeed there’s no blessed way to iterate on an output of array outside
. The snippet above may work but I’m curious why you think it’s better than a loop inside apply?
i've had this same problem and similar solution, or sometimes just having to know the total count ahead of time. the reason is because you aren't supposed to create pulumi resources inside of an Apply, at least that is what I was mostly sure of
Which is the lesser evil? The above or creating resources inside apply? Is the latter to be avoided at all cost, or just a guideline?
Just a guideline. I expect them to behave similarly
Okay, but preview won't work for resources created in apply, right?
It will not show those resources initially, yes. I suppose it won’t work for your example either.