I keep fighting outputs... given an `Output<Imm...
# dotnet
w
I keep fighting outputs... given an
Output<ImmutableArray<string>>
(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
OutputUtilities
.
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 });
}
t
Indeed there’s no blessed way to iterate on an output of array outside
apply
. The snippet above may work but I’m curious why you think it’s better than a loop inside apply?
b
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
w
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?
t
Just a guideline. I expect them to behave similarly
w
Okay, but preview won't work for resources created in apply, right?
t
It will not show those resources initially, yes. I suppose it won’t work for your example either.