Documentation
¶
Overview ¶
Package state manages terraform state.
Index ¶
- Variables
- func NewService(opts Options) *service
- type Client
- func (c *Client) CreateStateVersion(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)
- func (c *Client) DeleteStateVersion(ctx context.Context, svID string) 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, workspaceID string, opts resource.PageOptions) (*resource.Page[*Version], 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
Constants ¶
This section is empty.
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") )
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 (*Client) DeleteStateVersion ¶
func (*Client) DownloadCurrentState ¶
func (*Client) DownloadState ¶
func (*Client) GetCurrentStateVersion ¶
func (*Client) ListStateVersions ¶
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 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
type VersionList ¶
type VersionList struct {
*resource.Pagination
Items []*Version
}
VersionList represents a list of state versions.