https://pulumi.com logo
#getting-started
Title
# getting-started
w

white-forest-65475

02/19/2023, 5:24 PM
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

billowy-army-68599

02/19/2023, 5:43 PM
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

white-forest-65475

02/19/2023, 5:48 PM
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

billowy-army-68599

02/19/2023, 5:54 PM
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

white-forest-65475

02/19/2023, 5:56 PM
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

billowy-army-68599

02/19/2023, 6:01 PM
I would generally never recommend that, your mileage may vary.
w

white-forest-65475

02/19/2023, 6:02 PM
When it comes to using a local service backend, what do you recommend?
b

billowy-army-68599

02/19/2023, 6:03 PM
the local backend is really for testing and trying things out, I’d recommend using an object store at a minimum
w

white-forest-65475

02/19/2023, 6:04 PM
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!