state

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package state manages terraform state.

Index

Constants

View Source
const (
	DefaultStateVersion = 4
)

Variables

This section is empty.

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 (c *Client) CreateStateVersion(ctx context.Context, opts CreateStateVersionOptions) (*Version, error)

func (*Client) DownloadCurrentState

func (c *Client) DownloadCurrentState(ctx context.Context, workspaceID string) ([]byte, 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.
}

type Options added in v0.0.32

type Options struct {
	logr.Logger

	WorkspaceService
	WorkspaceAuthorizer otf.Authorizer

	otf.Cache
	otf.DB
}

type Output added in v0.0.32

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

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)
	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

func (*Version) String added in v0.0.32

func (v *Version) String() string

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

type WorkspaceService = workspace.Service

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

Jump to

Keyboard shortcuts

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