This message was deleted.
# python
s
This message was deleted.
c
Hi @broad-morning-80838
Is there a way to get a list of resources in the stack with python? Something equivalent to
pulumi stack --show-urns
I'd go with
pulumi stack export
.
the yaml config will be used for creating new resource
Did you know that Pulumi has a yaml backend? https://www.pulumi.com/docs/intro/languages/yaml/
b
Hi @clever-painter-96148 thanks for the response! I was hoping to do it directly inside of a python script without shelling out and parsing cli output. I'd assumed something like
pulumi.stack.list_resources()
existed, but so far haven't found anything.
I have looked at the yaml backend! In my case, I'm using a single yaml file for a few different things, so I didn't want to necessarily adhere to the yaml format required for pulumi YAML
Looks like I can just subprocess
pulumi stack export
and make things work that way for now
Thanks @clever-painter-96148!
c
You can do this using the automation api : pulumi.automation.select_stack(‘foo’).export_stack()
b
Ohh thank you! I haven't looked at the automation API. Thanks so much @clever-painter-96148
c
Just starting with it and I already love it 😁
❤️ 1
b
@clever-painter-96148 sorry, hopefully last question! Have you used
export_stack
to get a list of resources in the stack? I'm not sure how to use the type
pulumi.automation._workspace.Deployment
I see that you can use it to import state back into the stack, but in my case I'm hoping to use it to determine if resources are tracked by pulumi or not yet, and conditionally either import resources that don't exist in the stack but do exist in AWS, or create/update resources that are net new in my config file. Ultimately I'm trying to use this yaml config to drive the management of these resources, but since many of them exist in AWS already and I'm trying to bring them under pulumi management for the first time, I need to handle those resources differently than resources created in the future with this program.
c
For example, here is how to get URNs:
Copy code
>>> from pulumi.automation import select_stack
>>> deployment=select_stack('dev',work_dir='.').export_stack().deployment
>>> urns=[r['urn'] for r in deployment['resources']]
b
Ah!
.deployment
is what I was missing. Thanks a million @clever-painter-96148
c
You're welcome. Have fun! 🙂