How do Pulumi stacks, stack references, and refresh operations affect production drift management?
Quick Answer
A Pulumi stack is an isolated instance of a program with its own state, configuration, secrets, and outputs. Stack references create contracts between stacks, while refresh reconciles Pulumi state with real provider state so plans are not based on stale assumptions.
Detailed Answer
Think of each stack as a branch office ledger. The network office can publish official subnet IDs, and the payments office can read them, but neither office should edit the other ledger by hand.
Pulumi uses stacks so the same infrastructure program can safely represent dev, staging, and production, or separate ownership domains. This design lets teams keep code reuse while preserving state isolation and access control.
During an update, Pulumi loads the program, reads stack config and secrets, evaluates resources, compares desired resources to state, asks providers for previews, and records resulting changes. Stack references expose selected outputs without merging ownership.
Production teams use stack policies, protected resources, explicit providers, CI previews, and scheduled refreshes. They monitor failed updates, pending operations, unexpected replacements, and drift in resources that are often modified manually during emergencies.
The tricky edge case is letting stack references become hidden global variables. If many application stacks read mutable network outputs, a network rename or replacement can cause broad downstream churn unless outputs are versioned and deprecation is planned.
Code Example
pulumi stack select org/payments/prod # Selects the production state boundary before previewing changes. pulumi refresh --yes # Reconciles Pulumi state with provider reality before planning a risky update. pulumi preview --diff # Shows exact proposed replacements, updates, and deletes for review. pulumi up --yes # Applies the reviewed infrastructure change.
Interview Tip
A junior engineer typically answers with the feature name and a happy-path command, but for a senior/architect role, the interviewer is actually looking for production judgment. Explain where the Pulumi control plane stores intent, how changes are rolled out, what telemetry proves the system is healthy, and what failure mode creates the largest blast radius. Strong answers include rollback behavior, ownership boundaries, permissions, and the exact signal you would page on.