boundless-waiter-17971
10/26/2025, 5:17 PMpulumi to work with a bazel-managed python environment? I think pulumi up is trying to install its own dependencies, which does not play well with bazel philosophy. Is there any way to combine the two? Or in general, how does pulumi deal with monorepo setups, where you tend to share all the libraries instead of creating many small python virtual environments?hallowed-baker-22997
10/31/2025, 11:29 PMhallowed-baker-22997
10/31/2025, 11:36 PMhallowed-baker-22997
11/01/2025, 12:22 AM# BUILD.bazel
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@pulumi_pip//:requirements.bzl", "requirement")
# Your Pulumi program - customize this with your infrastructure code
py_library(
name = "pulumi_program",
srcs = ["__main__.py"],
deps = [
# Add your Pulumi provider dependencies here
requirement("pulumi"),
requirement("pulumi-aws"),
],
)
# Bazel wrapper that execs Pulumi CLI with the right Python environment
py_binary(
name = "pulumi",
srcs = ["pulumi_wrapper.py"],
main = "pulumi_wrapper.py",
data = glob(["Pulumi*.yaml"]),
deps = [
":pulumi_program", # Include the program so deps are in PYTHONPATH
],
)
# pulumi_wrapper.py
#!/usr/bin/env python3
"""
Wrapper that execs Pulumi CLI with Bazel's Python environment.
Bazel's py_binary automatically sets up PYTHONPATH with all dependencies.
"""
import os
import sys
# Exec pulumi - PYTHONPATH is set by Bazel, Pulumi.yaml is in runfiles
os.execvp('pulumi', ['pulumi'] + sys.argv[1:])
# Pulumi.yaml
name: pulumi-bazel-example
runtime:
name: python
options:
virtualenv: none # We're using Bazel's Python environment, so tell pulumi not to try to manage the venv itself.
description: Example Pulumi program running in a Bazel environmenthallowed-baker-22997
11/01/2025, 12:23 AMbazel run :pulumi -- preview
this will invoke the wrapper program with correct deps for your program.
it'll immediately exec the pulumi cli, which will be run in an environment where it's able to directly run your program without needing to manage the virtual env itself, (since the environment is already set up by bazel)hallowed-baker-22997
11/01/2025, 12:24 AMboundless-waiter-17971
11/01/2025, 8:26 AMboundless-waiter-17971
11/01/2025, 8:26 AM