https://pulumi.com logo
#automation-api
Title
# automation-api
h

handsome-state-59775

08/26/2021, 4:49 PM
[Python] How can I get a stack's config file path? I know it's
Pulumi.<stack>.yaml
, but can I avoid hardcoding this? If the last operation I do is
stack.set_all_config(...)
, I'm looking to follow it up with something like
print(stack.<config_file_path>)
. Is something like this available?
b

bored-activity-40468

08/26/2021, 5:12 PM
Since this is automation-api, are you passing which env to the application?
h

handsome-state-59775

08/26/2021, 5:28 PM
Hey, sorry - I don't quite understand what you mean by "passing env to application". If you mean environment variables, then I'm not (at least explicitly) referencing any in my program.
b

bored-activity-40468

08/26/2021, 5:50 PM
Before automation-api, you'd tell pulumi up, via setting the stack or passing the config file. With automation api how are you chosing which environment or stack to run?
I'm fairly new to Python but did some stuff and used the click command line library with automation-api. I'd pass
--environment test
to the application and that's how I'd determine which config to use.
l

lemon-agent-27707

08/26/2021, 6:16 PM
@handsome-state-59775 there are APIs to read and write the StackSettings object (which corresponds to the stack yaml file. You can see some examples in this test. This doesn't give you the location of the file, but does help you manipulate it: https://github.com/pulumi/pulumi/blob/master/sdk/python/lib/test/automation/test_local_workspace.py#L111-L137
Here is the impl of the underlying method. You can use similar logic to get the file name if you need it: https://github.com/pulumi/pulumi/blob/master/sdk/python/lib/pulumi/automation/_local_workspace.py#L126-L135
h

handsome-state-59775

08/26/2021, 6:48 PM
thanks, i'm resorting to similar logic for now. my only concern was if in case Pulumi changes this logic in the future, I may have a tough time debugging this