[Python] How can I get a stack's config file path?...
# automation-api
h
[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
Since this is automation-api, are you passing which env to the application?
h
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
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
@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
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