https://pulumi.com logo
#dotnet
Title
# dotnet
w

worried-city-86458

09/14/2021, 3:51 AM
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

tall-librarian-49374

09/14/2021, 7:46 AM
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

bumpy-grass-54508

09/14/2021, 1:11 PM
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

worried-city-86458

09/14/2021, 3:40 PM
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

tall-librarian-49374

09/14/2021, 3:56 PM
Just a guideline. I expect them to behave similarly
w

worried-city-86458

09/14/2021, 5:00 PM
Okay, but preview won't work for resources created in apply, right?
t

tall-librarian-49374

09/14/2021, 8:30 PM
It will not show those resources initially, yes. I suppose it won’t work for your example either.