Delete method. Delete is a synchronous operation that removes a resource from the infrastructure.
What Delete does
The agent callsDelete to remove a resource when:
- A user runs
formae destroy - A resource is removed from a forma file and
formae applyis run - A stack is being torn down
DeleteRequest
The agent sends aDeleteRequest when removing a resource:
ProgressResult. On success, set OperationStatusSuccess. On failure, set the appropriate ErrorCode. Notably, if the resource doesn’t exist, return NotFound (the agent treats this as success since the desired state is achieved).
Test
Add a test tosftp_test.go:
Test pattern
Implementation
Verify
Run the test to confirm Delete removes the file successfully:Handling NotFound
Now we need to handle another edge case: what happens when deleting a resource that doesn’t exist?Why NotFound on Delete is special
The agent treatsNotFound on Delete as success. Why? Because the desired outcome (resource gone) is already achieved. Whether formae deleted it or someone deleted it out-of-band, the end state is the same.
This makes Delete idempotent: calling Delete multiple times has the same effect as calling it once.
NotFound test
NotFound implementation
Add a check at the beginning of Delete to detect if the file exists:Verify
Summary
The idempotent behavior ensures that:
- Retrying a delete is safe
- Out-of-band deletions don’t cause errors
- The agent can reconcile state correctly
Next: 09 - List - Implement List for resource discovery

