githubEdit

Provider System

Spuff uses a provider abstraction layer that enables support for multiple cloud providers. This document explains how the system works.

Overview

flowchart TB
    subgraph cli["spuff CLI"]
        subgraph registry["Provider Registry"]
            factory["ProviderFactory"]
            create["create()"]
            boxprovider["Box<dyn Provider>"]
            factory --> create --> boxprovider
        end

        subgraph trait["Provider Trait"]
            methods["create_instance()  destroy_instance()  list_instances()<br/>get_instance()  wait_ready()  create_snapshot()<br/>list_snapshots()  delete_snapshot()  get_ssh_keys()"]
        end

        boxprovider --> trait

        subgraph providers["Implementations"]
            do["DigitalOcean<br/>Provider + Factory"]
            hetzner["Hetzner<br/>Provider + Factory"]
            aws["AWS<br/>Provider + Factory"]
        end

        trait --> do
        trait --> hetzner
        trait --> aws
    end

Architecture

The provider system follows the Registry Pattern, which enables:

  1. Extensibility: Add new providers without modifying existing code

  2. Dynamic discovery: List available providers at runtime

  3. Uniform configuration: All providers use the same creation interface

Main Components

File
Responsibility

src/provider/mod.rs

Provider trait and core types

src/provider/registry.rs

ProviderFactory and ProviderRegistry

src/provider/config.rs

InstanceRequest, ImageSpec, ProviderTimeouts

src/provider/error.rs

ProviderError with specific types

src/provider/digitalocean.rs

Reference implementation

Provider Creation Flow

Core Types

InstanceRequest

Configuration for creating an instance (provider-agnostic):

ImageSpec

Provider-agnostic image specification:

ProviderInstance

Instance returned by the provider:

InstanceStatus

Possible instance states:

ProviderError

Structured errors with retry information:

Current Providers

Provider
Status
File
Env Var

DigitalOcean

Stable

digitalocean.rs

DIGITALOCEAN_TOKEN

Hetzner

Planned

-

HETZNER_TOKEN

AWS EC2

Planned

-

AWS_ACCESS_KEY_ID

Documentation

Contributing

Want to add support for a new provider? Follow these steps:

  1. Open an issue to discuss the implementation

  2. Read the Creating a Provider guide

  3. Use the DigitalOcean implementation as reference

  4. Ensure adequate test coverage

  5. Update the documentation

Design Decisions

Consult the ADR to understand architectural decisions:

Last updated

Was this helpful?