state

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package state manages terraform state.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSerialLessThanCurrent = errors.New("the serial provided in the state file is not greater than the serial currently known remotely")
	ErrSerialMD5Mismatch     = errors.New("the MD5 hash of the state provided does not match what is currently known for the same serial number")
)
View Source
var ErrCurrentVersionDeletionAttempt = errors.New("deleting the current state version is not allowed")

Functions

func NewService

func NewService(opts Options) *service

Types

type Client

type Client struct {
	internal.JSONAPIClient
}

Client uses json-api according to the documented terraform cloud state version API [1] that OTF implements (we could use something different, something simpler but since the terraform CLI talks to OTF via json-api we might as well use this too...).

[1] https://developer.hashicorp.com/terraform/cloud-docs/api-docs/state-versions#state-versions-api

func (*Client) CreateStateVersion

func (c *Client) CreateStateVersion(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)

func (*Client) DeleteStateVersion

func (c *Client) DeleteStateVersion(ctx context.Context, svID string) error

func (*Client) DownloadCurrentState

func (c *Client) DownloadCurrentState(ctx context.Context, workspaceID string) ([]byte, error)

func (*Client) DownloadState

func (c *Client) DownloadState(ctx context.Context, svID string) ([]byte, error)

func (*Client) GetCurrentStateVersion

func (c *Client) GetCurrentStateVersion(ctx context.Context, workspaceID string) (*Version, error)

func (*Client) ListStateVersions

func (c *Client) ListStateVersions(ctx context.Context, workspaceID string, opts resource.PageOptions) (*resource.Page[*Version], error)

func (*Client) RollbackStateVersion

func (c *Client) RollbackStateVersion(ctx context.Context, svID string) (*Version, error)

type CreateStateVersionOptions

type CreateStateVersionOptions struct {
	State       []byte  // Terraform state file. Required.
	WorkspaceID *string // ID of state version's workspace. Required.
	Serial      *int64  // State serial number. If not provided then it is extracted from the state.
}

CreateStateVersionOptions are options for creating a state version.

type File

type File struct {
	Version int
	Serial  int64
	Lineage string
	Outputs map[string]FileOutput
}

File is the terraform state file contents

type FileOutput

type FileOutput struct {
	Value     json.RawMessage
	Sensitive bool
}

FileOutput is an output in the terraform state file

type Options

type Options struct {
	logr.Logger

	WorkspaceAuthorizer internal.Authorizer

	internal.Cache
	*sql.DB
}

type Output

type Output struct {
	ID             string
	Name           string
	Type           string
	Value          json.RawMessage
	Sensitive      bool
	StateVersionID string
}

type Service

type Service interface {
	// CreateStateVersion creates a state version for the given workspace using
	// the given state data.
	CreateStateVersion(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)
	// DownloadCurrentState downloads the current (latest) state for the given
	// workspace.
	DownloadCurrentState(ctx context.Context, workspaceID string) ([]byte, error)
	ListStateVersions(ctx context.Context, workspaceID string, opts resource.PageOptions) (*resource.Page[*Version], error)
	GetCurrentStateVersion(ctx context.Context, workspaceID string) (*Version, error)
	GetStateVersion(ctx context.Context, versionID string) (*Version, error)
	DeleteStateVersion(ctx context.Context, versionID string) error
	// RollbackStateVersion creates a state version by duplicating the
	// specified state version and sets it as the current state version for
	// the given workspace.
	RollbackStateVersion(ctx context.Context, versionID string) (*Version, error)
	DownloadState(ctx context.Context, versionID string) ([]byte, error)
	GetStateVersionOutput(ctx context.Context, outputID string) (*Output, error)
}

Service is the application Service for state

type StateService

type StateService = Service

Alias services so they don't conflict when nested together in struct

type StateVersionListOptions

type StateVersionListOptions struct {
	resource.PageOptions
	Organization string `schema:"filter[organization][name],required"`
	Workspace    string `schema:"filter[workspace][name],required"`
}

StateVersionListOptions represents the options for listing state versions.

type Version

type Version struct {
	ID          string
	CreatedAt   time.Time
	Serial      int64
	State       []byte             // state file
	Outputs     map[string]*Output // state version has many outputs
	WorkspaceID string             // state version belongs to a workspace
}

Version is a specific Version of terraform state. It includes important metadata as well as the state file itself.

https://developer.hashicorp.com/terraform/cloud-docs/api-docs/state-versions

func (*Version) Clone

func (v *Version) Clone() (*Version, error)

Clone makes a copy albeit with new identifiers.

func (*Version) String

func (v *Version) String() string

type VersionList

type VersionList struct {
	*resource.Pagination
	Items []*Version
}

VersionList represents a list of state versions.

Jump to

Keyboard shortcuts

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