I'm using the pulumi automation api in a go cli to...
# golang
b
I'm using the pulumi automation api in a go cli tool and really enjoying it so far. It's still a bit fuzzy to me what the requirements/dependencies are for the automation api though. Specifically, is the pulumi cli a hard dependency to use the automation api? Reason I ask is because I would love for users to be able to install the binary and use it as is while minimizing prerequisites/dependencies. This would also simplify containerizing the app. This is also ties into another question I have about pulumi's state management. Is there a way to have state management completely self-contained in a Go binary? i.e. Is it possible pulumi to create an s3 bucket to use for state storage, and then proceed to provision a stack that uses that bucket as a state backend? Or is this a chicken before the egg problem? Thanks
w
Hi Lucas! Very glad to hear you're enjoying it!
Specifically, is the pulumi cli a hard dependency to use the automation api?
Yes, the Pulumi CLI is a hard requirement for AutoAPI. We're exploring long term approaches to removing this requirement, but it's definitely a ways off.
Is there a way to have state management completely self-contained in a Go binary? i.e. Is it possible pulumi to create an s3 bucket to use for state storage, and then proceed to provision a stack that uses that bucket as a state backend?
Hmm... my answer is "yes and no" 😅 I would tackle this by creating a temporary directory (
/tmp/
), and using the filestate backend to write to that directory. From there, you can provision the stack, then delete the tmp directory.
Unfortunately, you can't "statelessly" create an S3 bucket, for example. You have to store the state somewhere. If you can write to a temp directory, you can always wipe the directory when you're done.
Just today I did something similar in a GitHub Action. I also wanted emphemeral state storage so I could run some performance tests.
Copy code
aws s3 mb <s3://my-bucket>
and when I was done...
Copy code
aws s3 rb --force <s3://my-bucket>
In this case, nothing about what I'm doing is "self-contained"; I'm invoking bash to run the aws command. Of course, you could use the AWS API from your Go program if you wanted. But unfortunately I don't think there's a way to "statelessly" bootstrap your environment.
b
Thanks Robbie! I've only been using the managed pulumi service backend, which is very convenient, but would like to offer more flexible, self-managed solutions to users for state storage. I like the idea of using the file backend to create the s3 bucket, thanks! I would likely use the AWS SDK in my program to create the bucket using the file state backend to be as self-contained as possible. I looked through the docs and some pulumi issues, but couldn't find the syntax for using the auto api to point to an s3 backend. Do you have any references you could point me to?
w
Sure! Glad to help 🙂 I think you want this example, and when you initialize the Project, you can use the Backend field to provide the path to the tmp directory.