Hello! I have a question about the Pulumi Automati...
# getting-started
w
Hello! I have a question about the Pulumi Automation SDK for Python. When using an inline program running on a stack created by a
auto.LocalWorkstation
, why am I getting errors about not having set PULUMI_ACCESS_TOKEN? How should I tell the automation SDK to please use a locally managed service backend for this stack? Here’s a small snippet I think is relevant:
Copy code
def get_stack(env: str, stack_name: Optional[str]) -> auto.Stack:
    if not stack_name:
        stack_name = env

    if env == "minikube":
        from .minikube import build_minikube
        program = build_minikube
    else:
        raise ValueError("Unknown environment: %s", env)

    workdir = PULUMI_WORKDIR / 'stack_name'
    if not workdir.exists():
        workdir.mkdir()

    # TODO provide secrets, etc. here
    workspace = auto.LocalWorkspace(work_dir=str(workdir), program=program)
    try:
        stack = workspace.select_stack(stack_name)
    except auto.CommandError:
        stack = workspace.create_stack(stack_name)

    assert stack is not None
    return stack
b
How should I tell the automation SDK to please use a locally managed service backend for this stack?
Run
pulumi login --local
before running the stack
w
Thanks! Is it intended that the automation API itself should be able to do this? It seems a bit awkward to build an automation API app that defines its own commands with an inline program and then preface it by saying “but first run `pulimi login --local`”… can this be done from the API?
it seems like it should be a workspace option or method, maybe?
b
it is a workspace option
Copy code
opts=LocalWorkspaceOptions(
        secrets_provider=SECRET_PROVIDER,
        work_dir=WORK_DIR,
        project_settings=ProjectSettings(
            name=PROJECT_NAME,
            runtime='python',
            backend=ProjectBackend(backend_url) # here
    )))
you can also set
PULUMI_BACKEND_URL
w
Oh I see, thank you!
this URL, would it make sense to make this just be
f"file://{WORK_DIR}/{STACK_NAME}"
? would that be a reasonable approach to managing pulumi service backend state in a git repo? (I’m aware there are some problems with this approach when it comes to eg. merge conflicts - that’s an issue for another day)
b
I would generally never recommend that, your mileage may vary.
w
When it comes to using a local service backend, what do you recommend?
b
the local backend is really for testing and trying things out, I’d recommend using an object store at a minimum
w
In the case of the minikube deployment target I’m working on here, it’s really always just going to be for local testing. Hmm, maybe I’ll just drop it in the user’s home directory then, since it doesn’t really need to be git managed, come to think of it. I definitely plan on using something like the s3 backend when it comes to my aws-ec2 target.
Thanks!