state

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MPL-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package state manages terraform state.

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var ErrCurrentVersionDeletionAttempt = errors.New("deleting the current state version is not allowed")

Functions

func NewCommand

func NewCommand(client *otfapi.Client) *cobra.Command

Types

type CLI

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

type Client

type Client struct {
	*otfapi.Client
}

func (*Client) Create

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

func (*Client) Delete

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

func (*Client) Download

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

func (*Client) DownloadCurrent

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

func (*Client) GetCurrent

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

func (*Client) List

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

func (*Client) Rollback

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

type CreateStateVersionOptions

type CreateStateVersionOptions struct {
	State       []byte  // Terraform state file. Optional.
	WorkspaceID *string // 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

func (r FileOutput) StringValue() string

func (FileOutput) Type

func (r FileOutput) Type() (string, error)

Type determines the HCL type of the output value

type Options

type Options struct {
	logr.Logger
	html.Renderer
	internal.Cache
	*sql.DB
	*tfeapi.Responder
	*surl.Signer

	WorkspaceService *workspace.Service
}

type Output

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

type Resource

type Resource struct {
	Name        string
	ProviderURI string `json:"provider"`
	Type        string
	Module      string
}

func (Resource) ModuleName

func (r Resource) ModuleName() string

func (Resource) Provider

func (r Resource) Provider() string

Provider extracts the provider from the provider URI

type Service

type Service struct {
	logr.Logger
	// contains filtered or unexported fields
}

Service provides access to state and state versions

func NewService

func NewService(opts Options) *Service

func (*Service) AddHandlers

func (a *Service) AddHandlers(r *mux.Router)

func (*Service) CanAccess

func (a *Service) CanAccess(ctx context.Context, action rbac.Action, svID string) (internal.Subject, error)

func (*Service) Create

func (a *Service) Create(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)

func (*Service) Delete

func (a *Service) Delete(ctx context.Context, versionID string) error

func (*Service) Download

func (a *Service) Download(ctx context.Context, svID string) ([]byte, error)

func (*Service) DownloadCurrent

func (a *Service) DownloadCurrent(ctx context.Context, workspaceID string) ([]byte, error)

func (*Service) Get

func (a *Service) Get(ctx context.Context, versionID string) (*Version, error)

func (*Service) GetCurrent

func (a *Service) GetCurrent(ctx context.Context, workspaceID string) (*Version, error)

func (*Service) GetOutput

func (a *Service) GetOutput(ctx context.Context, outputID string) (*Output, error)

func (*Service) List

func (a *Service) List(ctx context.Context, workspaceID string, opts resource.PageOptions) (*resource.Page[*Version], error)

func (*Service) Rollback

func (a *Service) Rollback(ctx context.Context, versionID string) (*Version, error)

func (*Service) Upload

func (a *Service) Upload(ctx context.Context, svID string, state []byte) error

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 Status

type Status string
const (
	Pending   Status = "pending"
	Finalized Status = "finalized"
	Discarded Status = "discarded"
)

type Version

type Version struct {
	ID          string             `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 string             `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

func (*Version) File

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

func (*Version) LogValue

func (v *Version) LogValue() slog.Value

func (*Version) String

func (v *Version) String() string

Jump to

Keyboard shortcuts

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