Skip to main content
This section implements the List method. List enables resource discovery: finding resources that exist in the infrastructure but aren’t yet managed by formae.

What is discovery?

Discovery allows formae to find “unmanaged” resources: resources that exist in your infrastructure but weren’t created through formae. This is useful for:
  • Importing existing infrastructure: bring pre-existing resources under formae management
  • Detecting out-of-band resources: find resources created outside of formae
  • Inventory auditing: get a complete view of what exists
The agent periodically runs discovery to scan for new resources. When it finds unmanaged resources, it can present them to the user for import.

List vs Read

  • List returns resource identifiers (native IDs)
  • Read is then called for each ID to get full properties
This two-phase approach allows efficient discovery. List is cheap (just IDs), and Read is only called when needed.

ListRequest

The agent sends a ListRequest during discovery:
List returns a ListResult containing the native IDs found:
If your infrastructure has many resources, implement pagination by setting NextPageToken. The agent will call List again with this token until it’s nil.

Test

Add a test for List to sftp_test.go:

Test pattern

Run the test to verify it fails

The test fails with not implemented.

Implementation

Key points

  1. Return native IDs: just the file paths, not full properties
  2. Handle empty gracefully: return empty list, not an error
  3. Pagination support: use NextPageToken for large result sets (not needed here)
  4. AdditionalProperties: can be used for discovery configuration (e.g., which directory to scan)

Verify

Run the test to confirm List discovers files correctly:
The test creates several files, then verifies that List returns all of them:

Discovery flow

Here’s how discovery works end-to-end:
  1. Agent calls List and the plugin returns all native IDs
  2. Agent compares to inventory and identifies unmanaged resources
  3. Agent calls Read for each unmanaged resource to get full properties
  4. Agent presents to user who can import into formae management

Non-discoverable resources

Some resource types cannot be listed. For example, the infrastructure API might not provide a list endpoint. In these cases, mark the resource as non-discoverable in its schema:
The agent will skip these resource types during discovery scans. Resources are discoverable by default, so you only need to set this when explicitly disabling discovery.

Summary

List enables resource discovery: With List implemented, your plugin supports the complete discovery workflow.
Next: 10 - Error Handling - Deep dive into OperationErrorCode patterns