This message was deleted.
s
This message was deleted.
1
e
To provide more context, the
pulumi.Output[List]
is a list of availability zones that were used in the creation of my AWS VPC in a different stack. They are being iterated over to create a
rds.ClusterInstance
for each availability zone
b
which language SDK are you using?
e
Python
Bumping this to see if anyone has a solution, I'm sure there's something trivial I'm missing. I've been unable to iterate through the output of another stack to create resources.
1
g
The reason for suggesting against creating resources inside
Output#apply
is that it causes incomplete graphs in some scenarios, like during the preview phase of the first deployment of that resource. But it is not forbidden. For your case I don't see any other option.
e
@green-school-95910 It didn't even create resources inside the apply function, I've got a nasty nasty hacky way of getting the availability zones now though:
Copy code
subprocess.run(["pulumi", "stack", "select", pulumi_config.require("network-stack")])
availability_zones = json.loads(subprocess.check_output(["pulumi", "stack", "output", "availability-zones"]).decode("utf-8"))
Surely this cannot be the only way of achieving this?
g
Have you tried just putting it inside apply?
e
I have, the resources I defined are not created
It looks something like this:
Copy code
def create_rds_cluster_instance(az_name):
    rds.ClusterInstance( ... )


network_stack = StackReference(pulumi_config.require("network-stack"))
availability_zones = network_stack.require_output("availability-zones")
availability_zones.apply(lambda zones: map(create_rds_cluster_instance, zones))
I've figured what's wrong, the actual creation should look something like this instead:
Copy code
def create_rds_cluster_instance(az_name):
    rds.ClusterInstance( ... )

network_stack = StackReference(pulumi_config.require("network-stack"))
availability_zones = network_stack.require_output("availability-zones")
availability_zones.apply(lambda zones: [create_rds_cluster_instance(z) for z in zones])
It's all working now. Cheers @green-school-95910!
Apologies for the brainfart, did not take into account
map
not evaluating all entries in the list
g
Yeah,
map
evaluates lazily as a generator.
👍 1