Documentation
¶
Overview ¶
Package state manages terraform state.
Index ¶
- Variables
- func NewCommand(client *otfhttp.Client) *cobra.Command
- type CLI
- type ChangeAction
- type Client
- func (c *Client) Create(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)
- func (c *Client) Delete(ctx context.Context, svID resource.TfeID) error
- func (c *Client) Download(ctx context.Context, svID resource.TfeID) ([]byte, error)
- func (c *Client) DownloadCurrent(ctx context.Context, workspaceID resource.TfeID) ([]byte, error)
- func (c *Client) GetCurrent(ctx context.Context, workspaceID resource.TfeID) (*Version, error)
- func (c *Client) List(ctx context.Context, workspaceID resource.TfeID, opts resource.PageOptions) (*resource.Page[*Version], error)
- func (c *Client) Rollback(ctx context.Context, svID resource.TfeID) (*Version, error)
- type CreateStateVersionOptions
- type File
- type FileOutput
- type Options
- type Output
- type OutputChange
- type Resource
- type ResourceChange
- type Service
- func (a *Service) AddHandlers(r *mux.Router)
- func (a *Service) Create(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)
- func (a *Service) Delete(ctx context.Context, versionID resource.TfeID) error
- func (a *Service) Download(ctx context.Context, svID resource.TfeID) ([]byte, error)
- func (a *Service) DownloadCurrent(ctx context.Context, workspaceID resource.TfeID) ([]byte, error)
- func (a *Service) Get(ctx context.Context, versionID resource.TfeID) (*Version, error)
- func (a *Service) GetCurrent(ctx context.Context, workspaceID resource.TfeID) (*Version, error)
- func (a *Service) GetOutput(ctx context.Context, outputID resource.TfeID) (*Output, error)
- func (a *Service) GetPrevious(ctx context.Context, sv *Version) (*Version, error)
- func (a *Service) List(ctx context.Context, workspaceID resource.TfeID, opts resource.PageOptions) (*resource.Page[*Version], error)
- func (a *Service) Rollback(ctx context.Context, versionID resource.TfeID) (*Version, error)
- func (a *Service) Upload(ctx context.Context, svID resource.TfeID, state []byte) error
- type StateDiff
- type Status
- type TFERollbackStateVersionOptions
- type TFEStateVersion
- type TFEStateVersionCreateVersionOptions
- type TFEStateVersionList
- type TFEStateVersionOutput
- type TFEStateVersionStatus
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( ErrSerialNotGreaterThanCurrent = 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") ErrUploadNonPending = errors.New("cannot upload state to a state version with a non-pending status") )
var ErrCurrentVersionDeletionAttempt = errors.New("deleting the current state version is not allowed")
Functions ¶
Types ¶
type ChangeAction ¶ added in v0.5.16
type ChangeAction string
ChangeAction represents the type of change in a diff.
const ( ActionAdd ChangeAction = "add" ActionRemove ChangeAction = "remove" ActionChange ChangeAction = "change" )
type Client ¶
func (*Client) DownloadCurrent ¶ added in v0.2.2
func (*Client) GetCurrent ¶ added in v0.2.2
type CreateStateVersionOptions ¶
type CreateStateVersionOptions struct {
State []byte // Terraform state file. Optional.
WorkspaceID resource.TfeID // ID of state version's workspace. Required.
Serial *int64 // State serial number. Required.
}
CreateStateVersionOptions are options for creating a state version.
type File ¶
type File struct {
Version int
TerraformVersion string `json:"terraform_version"`
Serial int64
Lineage string
Outputs map[string]FileOutput
Resources []Resource
}
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
func (FileOutput) StringValue ¶ added in v0.1.3
func (r FileOutput) StringValue() string
func (FileOutput) Type ¶ added in v0.1.3
func (r FileOutput) Type() (string, error)
Type determines the HCL type of the output value
type OutputChange ¶ added in v0.5.16
type OutputChange struct {
Action ChangeAction
Name string
Old *FileOutput
New *FileOutput
}
OutputChange is an output entry in a state diff.
type Resource ¶ added in v0.1.3
func (Resource) ModuleName ¶ added in v0.1.3
type ResourceChange ¶ added in v0.5.16
type ResourceChange struct {
Action ChangeAction
Resource Resource
}
ResourceChange is a resource entry in a state diff.
type Service ¶
type Service struct {
logr.Logger
*authz.Authorizer
// contains filtered or unexported fields
}
Service provides access to state and state versions
func NewService ¶
func (*Service) AddHandlers ¶ added in v0.2.2
func (*Service) DownloadCurrent ¶ added in v0.2.2
func (*Service) GetCurrent ¶ added in v0.2.2
func (*Service) GetPrevious ¶ added in v0.5.16
GetPrevious returns the finalized state version that immediately precedes sv (by serial) in the same workspace. Returns ErrResourceNotFound when sv is the first version.
type StateDiff ¶ added in v0.5.16
type StateDiff struct {
Resources []ResourceChange
Outputs []OutputChange
}
StateDiff is the diff between two state files.
func Diff ¶ added in v0.5.16
Diff computes the diff between two state files. from may be nil (first version), in which case every entry in to is treated as an addition.
func (StateDiff) HasChanges ¶ added in v0.5.16
HasChanges returns true when the diff contains at least one change.
type TFERollbackStateVersionOptions ¶ added in v0.3.17
type TFERollbackStateVersionOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,state-versions"`
// Specifies state version to rollback to. Only its ID is specified.
RollbackStateVersion *TFEStateVersion `jsonapi:"relationship" json:"state-version"`
}
TFERollbackStateVersionOptions are options for rolling back a state version
type TFEStateVersion ¶ added in v0.3.17
type TFEStateVersion struct {
ID resource.TfeID `jsonapi:"primary,state-versions"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
DownloadURL string `jsonapi:"attribute" json:"hosted-state-download-url"`
UploadURL string `jsonapi:"attribute" json:"hosted-state-upload-url"`
JSONUploadURL string `jsonapi:"attribute" json:"hosted-json-state-upload-url"`
Status TFEStateVersionStatus `jsonapi:"attribute" json:"status"`
Serial int64 `jsonapi:"attribute" json:"serial"`
VCSCommitSHA string `jsonapi:"attribute" json:"vcs-commit-sha"`
ResourcesProcessed bool `jsonapi:"attribute" json:"resources-processed"`
StateVersion int `jsonapi:"attribute" json:"state-version"`
TerraformVersion string `jsonapi:"attribute" json:"terraform-version"`
// Relations
Outputs []*TFEStateVersionOutput `jsonapi:"relationship" json:"outputs"`
}
TFEStateVersion is a state version suitable for marshaling into JSONAPI
type TFEStateVersionCreateVersionOptions ¶ added in v0.3.17
type TFEStateVersionCreateVersionOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,state-versions"`
// The lineage of the state.
Lineage *string `jsonapi:"attribute" json:"lineage,omitempty"`
// The MD5 hash of the state version.
MD5 *string `jsonapi:"attribute" json:"md5"`
// The serial of the state.
Serial *int64 `jsonapi:"attribute" json:"serial"`
// The base64 encoded state.
State *string `jsonapi:"attribute" json:"state"`
// Force can be set to skip certain validations. Wrong use of this flag can
// cause data loss, so USE WITH CAUTION!
Force *bool `jsonapi:"attribute" json:"force"`
}
TFEStateVersionCreateVersionOptions are options for creating a state version via JSONAPI
type TFEStateVersionList ¶ added in v0.3.17
type TFEStateVersionList struct {
*types.Pagination
Items []*TFEStateVersion
}
TFEStateVersionList is a list of state versions suitable for marshaling into JSONAPI
type TFEStateVersionOutput ¶ added in v0.3.17
type TFEStateVersionStatus ¶ added in v0.3.17
type TFEStateVersionStatus string
TFEStateVersionStatus are available state version status values
const ( StateVersionPending TFEStateVersionStatus = "pending" StateVersionFinalized TFEStateVersionStatus = "finalized" StateVersionDiscarded TFEStateVersionStatus = "discarded" )
Available state version statuses.
type Version ¶
type Version struct {
ID resource.TfeID `jsonapi:"primary,state-versions"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
Serial int64 `jsonapi:"attribute" json:"serial"`
State []byte `jsonapi:"attribute" json:"state"`
Status Status `jsonapi:"attribute" json:"status"`
Outputs map[string]*Output `jsonapi:"attribute" json:"outputs"`
WorkspaceID resource.TfeID `jsonapi:"attribute" json:"workspace-id"`
}
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