Pcornel
Automation · Idempotency

Create-if-Missing

Cheat sheet · https://pcornel.dk/topic.php?topic=5999

Back to the Topic

Answer

Create-if-missing is an idempotent pattern: check whether a resource exists and create it only if it does not, such as a user, folder or VLAN, so reruns do not create duplicates or fail.

Remember

  • Look up the resource before creating it.
  • Use a unique key for the lookup.
  • Report whether it was created or already existed.

First checks

  • Check existence before create — guard
  • Unique keys for lookup — identification
  • Handle 409/already exists as success — idempotency

Verify in this order

lookup → missing? create : no-op

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5999

Confirmation

Confirm action

Continue?