https://pulumi.com logo
#general
Title
# general
l

little-book-13693

06/23/2022, 7:01 PM
Copy code
if "foo" in outputs:
    TypeError: argument of type 'Output' is not iterable
b

billowy-army-68599

06/23/2022, 7:10 PM
you are running into the async nature of outputs. Outputs aren't iterable because they haven't resolved yet. You need to do the check inside an `apply`:
Copy code
stack_reference.output.apply(lambda: i if i // do something
l

little-book-13693

06/23/2022, 7:11 PM
Ok thanks, can i not extract the list of outputs that are currently there ?
b

billowy-army-68599

06/23/2022, 7:12 PM
can you elaborate what you mean by extract?
l

little-book-13693

06/23/2022, 7:13 PM
sure, so this works:
Copy code
outputs = stack_reference.outputs.apply(lambda outputs: [output for output in outputs])
pulumi.export("outputs", outputs)
it displays the list of output keys
I would now like to check, if a key exists in this list.
like would this work ?
Copy code
def stack_contains_output(stack_reference, output_name):
    return outputs.apply(lambda outputs: True if output_name in outputs else False)
b

billowy-army-68599

06/23/2022, 7:16 PM
yes basically, if you're inside the
apply
you can treat the object like a standard object because it's now resolved, so you can check however you'd like
l

little-book-13693

06/23/2022, 7:17 PM
Oh nice, yeh it works! thank you!
b

billowy-army-68599

06/23/2022, 7:18 PM
this might help with some additional context: https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply
l

little-book-13693

06/23/2022, 7:19 PM
thanks!
3 Views