All Pulumi CLI flags are now supported as environment variables
Posted on
With the release of Pulumi v3.208.0, all CLI flags can now be configured as environment variables. This addresses a common friction point of having to remember the same flags across multiple commands and of ensuring that your entire team uses consistent CLI options.
Use cases
An example use case might be that you want to always refresh state before operations, or re-run programs during refresh and destroy (using --run-program). But remembering to add --refresh every time is tedious.
Another example is you’re working on a specific subset of your infrastructure and need to pass the same --target or --exclude flags repeatedly across multiple operations.
You’re working in a CI environment where you want to skip interactive prompts and previews. That means adding --yes and --skip-preview to every single command in your pipeline.
The usual workaround, if there is no env var already, is writing wrapper scripts or shell aliases, but these become another thing to maintain and share across your team.
How it works
Any CLI flag can now be set as an environment variable. The naming convention is straightforward: prefix the flag name with PULUMI_OPTION_, and convert dashes to underscores.
For example:
export PULUMI_OPTION_REFRESH=true
Target specific resources without repeating flags:
export PULUMI_OPTION_TARGET=foo,bar
# Equivalent to: --target foo --target bar
This works for any flag the CLI accepts. The environment variable takes precedence if you don’t explicitly pass the flag on the command line.
Using with direnv for project-level defaults
This becomes particularly useful when combined with tools like direnv. You can define project-specific CLI defaults in a .envrc file at the root of your project:
# Enable very verbose logging for debugging purposes
export PULUMI_OPTION_VERBOSE=3
# Always refresh before any Pulumi operation
export PULUMI_OPTION_REFRESH=true
# Skip previews and any dialogs or user prompts
export PULUMI_OPTION_YES=true
export PULUMI_OPTION_SKIP_PREVIEW=true
Now, running direnv allow . in this directory means that, whenever we access this directory, these options will be automatically applied to all commands that we run until we leave the directory!
Wrapping up
We hope that this change makes Pulumi much easier to configure across a range of different environments, and gives you another tool for managing operation defaults across your team. Thanks for reading, and feel free to share any feedback on GitHub, X, or our Community Slack.
