backend

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBackendAdapter

func CreateBackendAdapter(config *BackendConfig) (statePkg.Backend, error)

CreateBackendAdapter creates an adapter for the appropriate backend type

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter bridges the new Backend interface with the legacy state.Backend interface

func NewAdapter

func NewAdapter(backend Backend, config *BackendConfig) *Adapter

NewAdapter creates a new backend adapter

func (*Adapter) Delete

func (a *Adapter) Delete(ctx context.Context, key string) error

Delete removes data for a given key (legacy interface)

func (*Adapter) Get

func (a *Adapter) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves data for a given key (legacy interface)

func (*Adapter) GetStateVersion

func (a *Adapter) GetStateVersion(ctx context.Context, key string, version int) ([]byte, error)

GetStateVersion retrieves a specific version (legacy interface)

func (*Adapter) List

func (a *Adapter) List(ctx context.Context, prefix string) ([]string, error)

List returns all keys with the given prefix (legacy interface)

func (*Adapter) ListStateVersions

func (a *Adapter) ListStateVersions(ctx context.Context, key string) ([]statePkg.StateVersion, error)

ListStateVersions returns versions for a state (legacy interface)

func (*Adapter) ListStates

func (a *Adapter) ListStates(ctx context.Context) ([]string, error)

ListStates returns all available states (legacy interface)

func (*Adapter) Lock

func (a *Adapter) Lock(ctx context.Context, key string) error

Lock acquires a lock on the state (legacy interface)

func (*Adapter) Put

func (a *Adapter) Put(ctx context.Context, key string, data []byte) error

Put stores data for a given key (legacy interface)

func (*Adapter) Unlock

func (a *Adapter) Unlock(ctx context.Context, key string) error

Unlock releases a lock on the state (legacy interface)

type AzureBackend

type AzureBackend struct {
	// contains filtered or unexported fields
}

AzureBackend implements the Backend interface for Azure Storage

func NewAzureBackend

func NewAzureBackend(cfg *BackendConfig) (*AzureBackend, error)

NewAzureBackend creates a new Azure Storage backend instance

func (*AzureBackend) CreateWorkspace

func (a *AzureBackend) CreateWorkspace(ctx context.Context, name string) error

CreateWorkspace creates a new workspace

func (*AzureBackend) DeleteWorkspace

func (a *AzureBackend) DeleteWorkspace(ctx context.Context, name string) error

DeleteWorkspace removes a workspace

func (*AzureBackend) GetLockInfo

func (a *AzureBackend) GetLockInfo(ctx context.Context) (*LockInfo, error)

GetLockInfo returns current lock information

func (*AzureBackend) GetMetadata

func (a *AzureBackend) GetMetadata() *BackendMetadata

GetMetadata returns backend metadata

func (*AzureBackend) GetVersion

func (a *AzureBackend) GetVersion(ctx context.Context, versionID string) (*StateData, error)

GetVersion retrieves a specific version of the state

func (*AzureBackend) GetVersions

func (a *AzureBackend) GetVersions(ctx context.Context) ([]*StateVersion, error)

GetVersions returns available state versions using blob snapshots

func (*AzureBackend) ListWorkspaces

func (a *AzureBackend) ListWorkspaces(ctx context.Context) ([]string, error)

ListWorkspaces returns available workspaces

func (*AzureBackend) Lock

func (a *AzureBackend) Lock(ctx context.Context, info *LockInfo) (string, error)

Lock acquires a lock on the state using blob leases

func (*AzureBackend) Pull

func (a *AzureBackend) Pull(ctx context.Context) (*StateData, error)

Pull retrieves the current state from Azure Blob Storage

func (*AzureBackend) Push

func (a *AzureBackend) Push(ctx context.Context, state *StateData) error

Push uploads state to Azure Blob Storage

func (*AzureBackend) SelectWorkspace

func (a *AzureBackend) SelectWorkspace(ctx context.Context, name string) error

SelectWorkspace switches to a different workspace

func (*AzureBackend) Unlock

func (a *AzureBackend) Unlock(ctx context.Context, lockID string) error

Unlock releases the lock on the state

func (*AzureBackend) Validate

func (a *AzureBackend) Validate(ctx context.Context) error

Validate checks if the backend is properly configured and accessible

type Backend

type Backend interface {
	// Pull retrieves the current state from the backend
	Pull(ctx context.Context) (*StateData, error)

	// Push uploads state to the backend
	Push(ctx context.Context, state *StateData) error

	// Lock acquires a lock on the state for safe operations
	Lock(ctx context.Context, info *LockInfo) (string, error)

	// Unlock releases the lock on the state
	Unlock(ctx context.Context, lockID string) error

	// GetVersions returns available state versions/history
	GetVersions(ctx context.Context) ([]*StateVersion, error)

	// GetVersion retrieves a specific version of the state
	GetVersion(ctx context.Context, versionID string) (*StateData, error)

	// ListWorkspaces returns available workspaces
	ListWorkspaces(ctx context.Context) ([]string, error)

	// SelectWorkspace switches to a different workspace
	SelectWorkspace(ctx context.Context, name string) error

	// CreateWorkspace creates a new workspace
	CreateWorkspace(ctx context.Context, name string) error

	// DeleteWorkspace removes a workspace
	DeleteWorkspace(ctx context.Context, name string) error

	// GetLockInfo returns current lock information
	GetLockInfo(ctx context.Context) (*LockInfo, error)

	// Validate checks if the backend is properly configured and accessible
	Validate(ctx context.Context) error

	// GetMetadata returns backend metadata
	GetMetadata() *BackendMetadata
}

Backend defines the interface for state backend operations

type BackendConfig

type BackendConfig struct {
	Type   string                 `json:"type"`
	Config map[string]interface{} `json:"config"`

	// Connection pool settings
	MaxConnections     int           `json:"max_connections,omitempty"`
	MaxIdleConnections int           `json:"max_idle_connections,omitempty"`
	ConnectionTimeout  time.Duration `json:"connection_timeout,omitempty"`
	IdleTimeout        time.Duration `json:"idle_timeout,omitempty"`

	// Retry settings
	MaxRetries   int           `json:"max_retries,omitempty"`
	RetryDelay   time.Duration `json:"retry_delay,omitempty"`
	RetryBackoff float64       `json:"retry_backoff,omitempty"`

	// Lock settings
	LockTimeout    time.Duration `json:"lock_timeout,omitempty"`
	LockRetryDelay time.Duration `json:"lock_retry_delay,omitempty"`
}

BackendConfig represents backend configuration

type BackendFactory

type BackendFactory interface {
	// CreateBackend creates a backend instance from configuration
	CreateBackend(config *BackendConfig) (Backend, error)

	// GetSupportedTypes returns list of supported backend types
	GetSupportedTypes() []string

	// ValidateConfig validates backend configuration
	ValidateConfig(config *BackendConfig) error
}

BackendFactory creates backend instances based on configuration

type BackendMetadata

type BackendMetadata struct {
	Type               string            `json:"type"`
	SupportsLocking    bool              `json:"supports_locking"`
	SupportsVersions   bool              `json:"supports_versions"`
	SupportsWorkspaces bool              `json:"supports_workspaces"`
	Configuration      map[string]string `json:"configuration"`
	Workspace          string            `json:"workspace"`
	StateKey           string            `json:"state_key"`
	LockTable          string            `json:"lock_table,omitempty"`
}

BackendMetadata contains metadata about the backend

type BackendState

type BackendState struct {
	Type      string                 `json:"type"`
	Config    map[string]interface{} `json:"config"`
	Hash      string                 `json:"hash"`
	Workspace string                 `json:"workspace,omitempty"`
}

BackendState represents the backend configuration in state

type ConnectionPool

type ConnectionPool interface {
	// Get retrieves a connection from the pool
	Get(ctx context.Context) (io.Closer, error)

	// Put returns a connection to the pool
	Put(conn io.Closer)

	// Close closes all connections in the pool
	Close() error

	// Stats returns pool statistics
	Stats() *PoolStats
}

ConnectionPool manages backend connections

type LockInfo

type LockInfo struct {
	ID        string    `json:"ID"`
	Path      string    `json:"Path"`
	Operation string    `json:"Operation"`
	Who       string    `json:"Who"`
	Version   string    `json:"Version"`
	Created   time.Time `json:"Created"`
	Info      string    `json:"Info"`
}

LockInfo represents state lock information

type PoolStats

type PoolStats struct {
	Active       int           `json:"active"`
	Idle         int           `json:"idle"`
	MaxOpen      int           `json:"max_open"`
	MaxIdle      int           `json:"max_idle"`
	WaitCount    int64         `json:"wait_count"`
	WaitDuration time.Duration `json:"wait_duration"`
	IdleTimeout  time.Duration `json:"idle_timeout"`
	Created      int64         `json:"created"`
	Closed       int64         `json:"closed"`
}

PoolStats contains connection pool statistics

type S3Backend

type S3Backend struct {
	// contains filtered or unexported fields
}

S3Backend implements the Backend interface for AWS S3

func NewS3Backend

func NewS3Backend(cfg *BackendConfig) (*S3Backend, error)

NewS3Backend creates a new S3 backend instance

func (*S3Backend) CreateWorkspace

func (s *S3Backend) CreateWorkspace(ctx context.Context, name string) error

CreateWorkspace creates a new workspace

func (*S3Backend) DeleteWorkspace

func (s *S3Backend) DeleteWorkspace(ctx context.Context, name string) error

DeleteWorkspace removes a workspace

func (*S3Backend) GetLockInfo

func (s *S3Backend) GetLockInfo(ctx context.Context) (*LockInfo, error)

GetLockInfo returns current lock information

func (*S3Backend) GetMetadata

func (s *S3Backend) GetMetadata() *BackendMetadata

GetMetadata returns backend metadata

func (*S3Backend) GetVersion

func (s *S3Backend) GetVersion(ctx context.Context, versionID string) (*StateData, error)

GetVersion retrieves a specific version of the state

func (*S3Backend) GetVersions

func (s *S3Backend) GetVersions(ctx context.Context) ([]*StateVersion, error)

GetVersions returns available state versions using S3 versioning

func (*S3Backend) ListWorkspaces

func (s *S3Backend) ListWorkspaces(ctx context.Context) ([]string, error)

ListWorkspaces returns available workspaces

func (*S3Backend) Lock

func (s *S3Backend) Lock(ctx context.Context, info *LockInfo) (string, error)

Lock acquires a lock on the state using DynamoDB

func (*S3Backend) Pull

func (s *S3Backend) Pull(ctx context.Context) (*StateData, error)

Pull retrieves the current state from S3

func (*S3Backend) Push

func (s *S3Backend) Push(ctx context.Context, state *StateData) error

Push uploads state to S3

func (*S3Backend) SelectWorkspace

func (s *S3Backend) SelectWorkspace(ctx context.Context, name string) error

SelectWorkspace switches to a different workspace

func (*S3Backend) Unlock

func (s *S3Backend) Unlock(ctx context.Context, lockID string) error

Unlock releases the lock on the state

func (*S3Backend) Validate

func (s *S3Backend) Validate(ctx context.Context) error

Validate checks if the backend is properly configured and accessible

type S3ConnectionPool

type S3ConnectionPool struct {
	// contains filtered or unexported fields
}

S3ConnectionPool manages S3 client connections

func NewS3ConnectionPool

func NewS3ConnectionPool(maxOpen, maxIdle int, idleTimeout time.Duration) *S3ConnectionPool

NewS3ConnectionPool creates a new connection pool

type StateData

type StateData struct {
	Version          int                    `json:"version"`
	TerraformVersion string                 `json:"terraform_version"`
	Serial           uint64                 `json:"serial"`
	Lineage          string                 `json:"lineage"`
	Data             []byte                 `json:"-"`
	Resources        []StateResource        `json:"resources,omitempty"`
	Outputs          map[string]interface{} `json:"outputs,omitempty"`
	Backend          *BackendState          `json:"backend,omitempty"`
	Checksum         string                 `json:"checksum,omitempty"`
	LastModified     time.Time              `json:"last_modified"`
	Size             int64                  `json:"size"`
}

StateData represents Terraform state data

type StateResource

type StateResource struct {
	Mode      string                  `json:"mode"`
	Type      string                  `json:"type"`
	Name      string                  `json:"name"`
	Provider  string                  `json:"provider"`
	Instances []StateResourceInstance `json:"instances"`
}

StateResource represents a resource in the state

type StateResourceInstance

type StateResourceInstance struct {
	SchemaVersion       int                    `json:"schema_version"`
	Attributes          map[string]interface{} `json:"attributes"`
	Dependencies        []string               `json:"dependencies,omitempty"`
	CreateBeforeDestroy bool                   `json:"create_before_destroy,omitempty"`
}

StateResourceInstance represents an instance of a resource

type StateVersion

type StateVersion struct {
	ID          string    `json:"id"`
	VersionID   string    `json:"version_id"`
	Serial      uint64    `json:"serial"`
	Created     time.Time `json:"created"`
	CreatedBy   string    `json:"created_by,omitempty"`
	Size        int64     `json:"size"`
	Checksum    string    `json:"checksum,omitempty"`
	IsLatest    bool      `json:"is_latest"`
	Description string    `json:"description,omitempty"`
}

StateVersion represents a version of the state

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL