Documentation
¶
Overview ¶
Package state manages terraform state.
Index ¶
- Constants
- Variables
- func NewService(opts Options) *service
- type Client
- func (c *Client) CreateStateVersion(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)
- func (c *Client) DownloadCurrentState(ctx context.Context, workspaceID string) ([]byte, error)
- func (c *Client) DownloadState(ctx context.Context, svID string) ([]byte, error)
- func (c *Client) GetCurrentStateVersion(ctx context.Context, workspaceID string) (*Version, error)
- func (c *Client) ListStateVersions(ctx context.Context, options StateVersionListOptions) (*VersionList, error)
- func (c *Client) RollbackStateVersion(ctx context.Context, svID string) (*Version, error)
- type CreateStateVersionOptions
- type File
- type FileOutput
- type Options
- type Output
- type Service
- type StateService
- type StateVersionListOptions
- type Version
- type VersionList
- type WorkspaceService
Constants ¶
const (
DefaultStateVersion = 4
)
Variables ¶
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") )
Functions ¶
func NewService ¶
func NewService(opts Options) *service
Types ¶
type Client ¶
type Client struct {
otf.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 (*Client) DownloadCurrentState ¶
func (*Client) DownloadState ¶ added in v0.0.34
func (*Client) GetCurrentStateVersion ¶ added in v0.0.34
func (*Client) ListStateVersions ¶ added in v0.0.34
func (c *Client) ListStateVersions(ctx context.Context, options StateVersionListOptions) (*VersionList, error)
type CreateStateVersionOptions ¶ added in v0.0.32
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 ¶ added in v0.0.34
type File struct {
Version int
Serial int64
Lineage string
Outputs map[string]FileOutput
}
File is the terraform state File contents
type FileOutput ¶ added in v0.0.34
type FileOutput struct {
Value json.RawMessage
Sensitive bool
}
FileOutput is an output in the terraform state file
type Options ¶ added in v0.0.32
type Options struct {
logr.Logger
WorkspaceService
WorkspaceAuthorizer otf.Authorizer
otf.Cache
otf.DB
}
type Service ¶ added in v0.0.32
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, opts StateVersionListOptions) (*VersionList, error)
GetCurrentStateVersion(ctx context.Context, workspaceID string) (*Version, error)
GetStateVersion(ctx context.Context, versionID string) (*Version, 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 ¶ added in v0.0.32
type StateService = Service
type StateVersionListOptions ¶ added in v0.0.32
type StateVersionListOptions struct {
otf.ListOptions
Organization string `schema:"filter[organization][name],required"`
Workspace string `schema:"filter[workspace][name],required"`
}
StateVersionListOptions represents the options for listing state versions.
type Version ¶ added in v0.0.32
type Version struct {
ID string
CreatedAt time.Time
Serial int64
State []byte // state file
Outputs outputList // 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
type VersionList ¶ added in v0.0.32
type VersionList struct {
*otf.Pagination
Items []*Version
}
VersionList represents a list of state versions.
type WorkspaceService ¶ added in v0.0.32
Alias services so they don't conflict when nested together in struct