I’m using the automation api. Whenever I do an `au...
# python
g
I’m using the automation api. Whenever I do an
auto.create_or_select_stack()
or
auto.create_stack()
I receive the error
PULUMI_ACCESS_TOKEN must be set for login during non-interactive CLI sessions
. I want to use a local filesystem backend (I guess… I’d rather have an in-memory, disposable backend, see above, but ok). Can’t figure how to tell Pulumi that. All the docs I’ve seen say I should set a config on the stack, but this failure happens within the stack creation. I’ve even tried setting it in
Pulumi.yaml
even though my aim is not to have a Pulumi.yaml at all (I want to drive it all from code). Still no go. What’s the key to convincing pulumi.automation not to require a pulumi login?
m
Are you passing
LocalWorkspaceOptions
to
auto.create_or_select_stack()
? I can't find it in the Python SDK documentation, but you can look at the code here or look at the signature of
LocalWorkspace
, which you can find here. It allows you to define where you store your state etc. In your case, you'll want to make sure that the
ProjectSettings
are correct (see the docs.) You pass it to
create_or_select_stack
via
opts
as described here. If you do it like that, you don't need a Pulumi.yaml at all.
b
I recently encountered this problem and my solve was to add
pulumi login --local
prior to running my Pulumi tests that use the automation API. I’m not sure if this is the best way to solve the problem but I similarly tried using
LocalWorkspace
and could not resolve the issue.
m
Interesting! In the project we use the automation API we never use the Pulumi CLI. I cannot share any code directly, but happy to work out a minimal example with you. The following is a specific example of what I described above:
Copy code
from pulumi import automation as auto

project_settings = auto.ProjectSettings(
  name="local-project",
  runtime="python",
  backend=auto.ProjectBackend(url="<file://path/to/local/state>")
)

local_workspace_options = auto.LocalWorkspaceOptions(
   project_settings=project_settings
)

stack = auto.create_or_select_stack(..., opts=local_workspace_options)