Skip to content

Commit b04b3ab

Browse files
Controlling the CLI through environment variables (#16595)
* Controlling the CLI through environment variables * Top bit minus date * More front matter * edits, add meta image, social copy, date --------- Co-authored-by: meagancojocar <[email protected]>
1 parent e8c6aa1 commit b04b3ab

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: All Pulumi CLI flags are now supported as environment variables
3+
date: 2025-11-21
4+
meta_desc: "You can now configure all Pulumi CLI flags via environment variables, and use tools like direnv to define project-wide settings"
5+
meta_image: meta.png
6+
authors:
7+
- tom-harding
8+
tags:
9+
- features
10+
- iac
11+
- release
12+
- cli
13+
14+
social:
15+
twitter: |
16+
All Pulumi CLI flags now support environment variables! Set any flag with PULUMI_OPTION_*. Combine with direnv to version-control your team's CLI configuration. Available in v3.208.0+
17+
linkedin: |
18+
Pulumi v3.208.0 adds environment variable support for all CLI flags.
19+
20+
Key highlights:
21+
→ Set any CLI flag as an environment variable using PULUMI_OPTION_* prefix
22+
→ Version control your team's CLI defaults with direnv
23+
→ You no longer need to repeat --verbose, --refresh, --target flags across commands
24+
→ Command-line flags override env vars when you need flexibility
25+
26+
This means your CLI configuration can live alongside your infrastructure code, consistent across your entire team.
27+
---
28+
29+
With the release of [Pulumi v3.208.0](https://github.com/pulumi/pulumi/releases/tag/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.
30+
31+
<!--more-->
32+
33+
## Use cases
34+
35+
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`](https://www.pulumi.com/blog/improved-refresh-destroy-experience/)). But remembering to add `--refresh` every time is tedious.
36+
37+
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.
38+
39+
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.
40+
41+
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.
42+
43+
## How it works
44+
45+
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.
46+
47+
For example:
48+
49+
```shell
50+
export PULUMI_OPTION_REFRESH=true
51+
```
52+
53+
Target specific resources without repeating flags:
54+
55+
```shell
56+
export PULUMI_OPTION_TARGET=foo,bar
57+
# Equivalent to: --target foo --target bar
58+
```
59+
60+
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.
61+
62+
## Using with direnv for project-level defaults
63+
64+
This becomes particularly useful when combined with tools like [`direnv`](https://direnv.net/). You can define project-specific CLI defaults in a `.envrc` file at the root of your project:
65+
66+
```shell
67+
# Enable very verbose logging for debugging purposes
68+
export PULUMI_OPTION_VERBOSE=3
69+
70+
# Always refresh before any Pulumi operation
71+
export PULUMI_OPTION_REFRESH=true
72+
73+
# Skip previews and any dialogs or user prompts
74+
export PULUMI_OPTION_YES=true
75+
export PULUMI_OPTION_SKIP_PREVIEW=true
76+
```
77+
78+
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\!
79+
80+
## Wrapping up
81+
82+
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](https://github.com/pulumi/pulumi), [X](https://twitter.com/pulumicorp), or our [Community Slack](https://slack.pulumi.com/).
496 KB
Loading

0 commit comments

Comments
 (0)