Has anyone tried running <Pulumi> with the code ma...
# general
i
Has anyone tried running Pulumi with the code managed as part of a Pants repo? More details in thread…
Pulumi works by having the user run an external executable, which in turn runs your python code. The Pulumi CLI needs to be executed inside an activated venv that contains all the dependencies needed in your code. I can do this by doing a pants export, but I was wondering if there was a way of doing it without having to export the venv, rather by doing some magic to allow the cli to run “inside” the pex?
b
While I haven't yet migrated us over to using
pants export
, we're doing the spiritual equivalent of that now managing our own venv (I think this dates back to before
pants export
existed). It's a little odd (and I have to do some path tweaking with
sys.path.insert
to make everything play nicely), but it works well enough. I think somebody here in this Slack was working on a Pants Pulumi plugin at one point; not sure if anything has come of that just yet, though.
(and I've got a repo with 22 Pulumi projects in it 😅)
A nice thing about Pants with Pulumi Python projects is that I can use Pants to figure out which Pulumi projects (if any) were changed in any given pull request and then only run those projects in our CI pipeline. You can use `files`/`resources` targets to capture dependencies on the YAML files, too.
One alternative you can look into is the Pulumi Automation API... in the past, I've used that to wrap up the execution logic for a number of interrelated Pulumi projects in Python code, stick it behind a nice Click / Typer CLI, and then run it through Pants with a
pants run my_automation_app
call. That actually works quite well.
(I think I'm going to be moving away from that particular implementation soon for other reasons, but depending on your needs, it may be just the ticket. The Automation API is relatively straightforward to use, and you can get things up and running with only a thin veneer of code on top of your existing projects.)
Happy to chat more if you've got any questions about details of any of these approaches.
h
A venv-mode pex turns itself into a venv on first run, you could write a shim that leverages that?