What is your strategy for writing idempotent automation scripts?
Implement the strategy for resource operations. Each operation must produce the same final state when replayed any number of times. ensure_present creates or replaces a resource configuration, while ensure_absent removes it if present.
Input: initial_state, a dictionary from resource names to configuration dictionaries, and operations, a list of operation dictionaries. Output: a new dictionary representing the final state. Do not mutate initial_state.
def apply_operations(initial_state, operations):