Using the Pulumi Automation API without the Pulumi Service

Viewed 45

I am trying to build a CLI utilizing the Pulumi Automation API and would like to store the required Pulumi state in a GCP Storage Bucket (using the Pulumi CLI I can do this using pulumi login gs://some-bucket).

In the documentation I could not find information about this, the only login-related topic mentioned is the use of a Pulumi Access Token used to talk to the Pulumi Service - which I'm trying to avoid.

Does the option to use the Automation API without using the Pulumi Service even exist?

2 Answers

The automation API doesn't manage the mechanism by which you login to Pulumi. You're expected to have selected your backend and logged into it before you start using it.

Once you've logged in, set a project name that doesn't use an organization features, and it should just work. Here's an example using the Python SDK


# create_pulumi_program is a function that has a Pulumi program in it
def pulumi_program():
  return create_pulumi_program(stack_name, image, int(port))


# create a workspace
stack = auto.create_stack(
  stack_name=str("dev"),
  project_name="my-project", # with the OSS backends, you cannot do "my-org/my-project"
  program=pulumi_program,
)

I've had a similar problem and used the following but I don't understand it yet (first day with pulumi). Maybe it helps you to figure it out:

// Not sure if these need to be the same or if they have a different role
const STACK_PROJECT = "not-sure-what-this-projects-role-is"
const WORKSPACE_PROJECT= "not-sure-what-this-projects-role-is"

const stack = await LocalWorkspace.createOrSelectStack(
    {
      stackName: "some-stack-name",
      projectName: STACK_PROJECT,
      program: someInlineProgram,
    },
    {
      projectSettings: {
        name: WORKSPACE_PROJECT,
        // Does this need to be nodejs? Not sure...
        runtime: "nodejs",
        backend: {
          // Modify this for your purposes.
          // It seems to have the same effect as a prior `pulumi login {url}`
          url: "file://~",
        },
      },
    }
)
Related