Hi, I have a list of Outputs, but I can't find a w...
# python
a
Hi, I have a list of Outputs, but I can't find a way to order it. The problem that I'm trying to solve is to guarantee consistency when running `pulumi_aws.ec2.getNetworkInterfaces`: https://www.pulumi.com/registry/packages/aws/api-docs/ec2/getnetworkinterfaces/ If I don't order the network interfaces, then they can come in any order and make my Pulumi runs different from one run to the next I've tried using
.apply()
, but Pulumi complains since it can't be used against a list.
w
Hi, I’m not sure, if this is what you are searching, but you can give the following a try:
Copy code
sorted_network_interfaces = ec2.get_network_interfaces_output().apply(
  lambda network_interfaces: sorted(network_interfaces.ids)
)
If you have for instance multiple Outputs, you can use
pulumi.Output.all():
Copy code
sorted_network_interfaces1 = ec2.get_network_interfaces_output().apply(
  lambda network_interfaces: sorted(network_interfaces.ids),
)
sorted_network_interfaces2 = ec2.get_network_interfaces_output().apply(
  lambda network_interfaces: network_interfaces.ids,
)
sorted_network_interfaces = pulumi.Output.all(sorted_network_interfaces1, sorted_network_interfaces2).apply(
  lambda args: sorted((*args[0], *args[1])),
)
This example will sort the same network interfaces in one list, so if you need unique items, you need to put it into a set and then sort.
a
Hi, so that's what I ended up doing, using the
_output()
variant. That gives me an Output that is a list, so
apply()
can run. It doesn't seem to be possible to do this on a list of Outputs. Thanks!
w
Do you need just the sorted ids?
Copy code
sorted_network_interfaces = sorted(ec2.get_network_interfaces().ids)
a
No, I then need to manipulate it in different ways, so I definitely need the outputs
But I'm all good now, thank you!
w
Okay. 🙂