Use this when an operation compares against a desired value.
Desired State · Idempotency
Desired state in idempotency is the target description the operation compares against, such as 'package present at version 1.2', so it knows whether any change is needed.
1. Idempotency needs an explicit desired state.
2. From code/SoT.
3. Compare with actual.
4. Act on differences.
5. Report.
desired state → comparison → actions
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The strongest idempotency verification is a two-run test plus independent state read-back. Capture current state, apply the desired state once, verify convergence, then apply the exact same revision again with the same inputs. The second run should report no unexpected changes and the consumer-visible state should remain equivalent. Compare semantic properties rather than raw text when the platform normalizes order, generated metadata or formatting. Also test a deliberately drifted state so the automation shows that it can detect and correct a real difference instead of always returning 'no change'. Where available, retain provider/resource changed flags and before/after values, but treat them as intermediate evidence; an external read path should confirm the target. This test separates true idempotency from a command that merely returns success repeatedly while doing unnecessary work.
Step 2 Common mistakes Narrow the fault
- Desired state undefined for some attributes.
Step 3 Where it fails Narrow the fault
Do not conflate idempotency with determinism, transactionality, safety or correctness. An idempotent operation can converge to the wrong desired value; a deterministic operation can repeatedly produce the same unwanted side effect; and a failed partial transaction can leave state that the next run must reconcile. The first boundary is state observation—if current state cannot be read reliably, idempotency claims are weak. The next is comparison/normalization, then mutation semantics, then downstream side effects. Diagnose which boundary is producing repeated change before adding more guards. If every run reports drift, determine whether the desired value is unstable, the read model is incomplete, the provider normalizes differently, or another controller is changing the same property. Re-run the exact two-pass verification after remediation and confirm both no-op behavior and correct end state.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Desired state defines the target.
- Compare before acting.
- Report differences.
- Desired state defined explicitly — input
- Single source for desired state — authority
- Comparison logic — diff
ReferenceWhy it matters1 section · depth on demand
In depth
In idempotency design, desired state is what makes repeated execution safe: the automation describes the end result ("VLAN 120 exists with name users"), so a rerun compares and finds nothing to do.
| Imperative step | Desired-state form |
|---|---|
vlan 120 + name users lines | ios_vlans with state: merged |
useradd | user: state=present |
| POST create | PUT full object |
When a tool lacks a desired-state module, write a small wrapper that reads current state first and only acts on differences.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
Idempotency links desired state to repeatable enforcement: once the managed resource already satisfies the declaration, applying the same operation again should not create additional semantic change. That requires an observable current-state model, a comparison rule and a mutation that converges only the relevant difference. Desired state in this context is therefore the fixed point of the operation, not merely a set of commands that happen to work twice. Some operations are naturally idempotent because they express state ('present', 'enabled', value equals X); others require guards, resource identifiers or compare-before-write logic. Idempotency is also scoped: a task can be idempotent for a file's content while still causing timestamps, restart counters, generated IDs or downstream side effects to change. Define which properties must stabilize and which effects are intentionally repeatable.
ReferenceConfiguration & state1 section · depth on demand
Lifecycle
Design idempotent automation from the state contract backward. Identify the authoritative desired properties, define how current state is read and normalized, then mutate only when the comparison says convergence is required. Avoid using transient outputs such as timestamps, random IDs or unordered serialization as desired values unless they are deliberately stabilized. When a provider/API exposes eventual consistency, separate 'write accepted' from 'state converged' and use bounded retries around read-back rather than repeatedly issuing the mutation. Version the desired state and comparison semantics with the automation so a code change that intentionally redefines equivalence is reviewable. If an operation has unavoidable side effects, document it as non-idempotent and place it behind an explicit condition or one-time lifecycle event instead of hiding that behavior under a desired-state label.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Idempotency > Desired State. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://help.puppet.com/core/current/Content/PuppetCore/key_concepts_puppet.htm · confidence 94%Quick lookup tables
Idempotency → Desired State · operational reference
Context-specific ownership, verification, output and failure-boundary lookup for Idempotency → Desired State.
| Layer | Idempotency → Desired State operational reference |
|---|---|
| Context identity | Declarative configuration management / Puppet current + exact revision/input/target identity |
| Persistent intent | Versioned contract/configuration with explicit ownership and prerequisites |
| Verification | Validate inputs/read current state → exercise bounded operation → independent target read-back |
| Output contract | Preserve structured status/IDs/properties before human formatting |
| Failure boundary | Separate source/input/engine/controller execution from downstream target outcome |
Deep reference
Healthy vs suspicious evidence
Output interpretation
Idempotency output should make convergence explicit: observed-before, desired, whether a mutation was required, observed-after, and the change count on a subsequent run. A second successful exit code is insufficient because the operation might still restart a service, rewrite a file, recreate an object or emit duplicate records every time. Normalize known volatile fields before comparison and document that normalization so it does not mask meaningful change. If a tool provides changed, diff or plan results, preserve them as structured data. For APIs, record stable resource IDs and selected properties rather than entire responses full of timestamps. A good output contract lets an operator distinguish 'already correct', 'changed to desired', 'accepted but not yet converged', and 'failed to observe state' without inferring those states from generic log text.