Preview refresh behavior limits developer iteration speed in Pulumi
0 reputation · 13 Nov 2023, 05:52 UTC
0 reputation · 13 Nov 2023, 05:52 UTC
Developers want `pulumi preview` to show an accurate drift detection without manually adding `--refresh` each time, so that the preview step remains reliable in a repeatable development workflow. The current behavior requires the explicit `--refresh` flag to synchronize state with remote resources, which guarantees correctness but can increase preview duration and cloud‑API charges, especially in large stacks. Pulumi permits setting `refresh: true` in the project configuration to make `pulumi up` refresh by default, yet the preview command still ignores this setting and leaves the decision to the user, creating a trade‑off between speed and fidelity.
Given these constraints, what is the recommended approach to align preview accuracy with developer efficiency?
34775 reputation · 13 Nov 2023, 17:14 UTC
In short, the current best practice is to keep refresh: true for pulumi up only, and use pulumi preview --refresh when you need a drift‑aware plan. Pulumi does not yet support a project‑level previewRefresh: true or a dedicated --refresh-preview flag, and there is no built‑in cache that persists refreshed state across preview runs.
pulumi preview --refresh for critical drift checks. When you are about to deploy or when you suspect external changes, run pulumi preview --refresh to guarantee the plan reflects the current cloud state.refresh: true only for pulumi up. This keeps normal deployments up‑to‑date while preserving preview speed.--refresh run and reuses it for subsequent previews until the TTL expires. This reduces API calls while still catching recent drift.--refresh does not exceed your budget. If it does, adjust the cache TTL or limit the number of preview runs per day.previewRefresh configuration option or a --refresh-preview flag are welcome in the Pulumi repo.If you are experiencing unexpected drift that is not caught by pulumi preview, confirm the following:
pulumi version)refresh: true set in Pulumi.yaml?Providing these details will help refine the recommendation further.
Use comments to ask for clarification. Post a solution as an answer.
6,260 reputation · 13 Nov 2023, 08:07 UTC
Instead of a full pulumi preview --refresh, run pulumi refresh --target <urn> on resources most prone to out-of-band changes (e.g., managed databases, DNS records) before a regular preview. This limits provider read calls to a known subset while still catching drift where it matters most.
A nightly or on-merge pulumi refresh in CI keeps the state file current for daytime previews without adding latency to every developer iteration. The Automation API can wrap this logic if you need conditional refresh based on staleness thresholds.
Whether refresh: true in Pulumi.yaml affects preview has changed across CLI releases. Run pulumi preview --help and test a drift scenario on your installed version before codifying a workflow.