tfstate

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MPL-2.0 Imports: 36 Imported by: 17

Documentation

Index

Constants

View Source
const S3EndpointEnvKey = "AWS_ENDPOINT_URL_S3"
View Source
const (
	StateVersion = 4
)

Variables

This section is empty.

Functions

func FuncMap added in v0.0.12

func FuncMap(ctx context.Context, stateLoc string, opts ...ReadURLOption) (template.FuncMap, error)

FuncMap provides a template.FuncMap tfstate based on URL and provide

func FuncMapWithName added in v0.0.12

func FuncMapWithName(ctx context.Context, name string, stateLoc string, opts ...ReadURLOption) (template.FuncMap, error)

FuncMapWithName provides a template.FuncMap. can lockup values from tfstate.

func JsonnetNativeFuncs added in v1.3.0

func JsonnetNativeFuncs(ctx context.Context, prefix, stateLoc string, opts ...ReadURLOption) ([]*jsonnet.NativeFunction, error)

JsonnetNativeFuncs provides the native functions for go-jsonnet.

func MustFuncMap added in v0.0.12

func MustFuncMap(ctx context.Context, stateLoc string, opts ...ReadURLOption) template.FuncMap

MustFuncMap is similar to FuncMap, but panics if it cannot get and parse tfstate.

func MustFuncMapWithName added in v0.0.12

func MustFuncMapWithName(ctx context.Context, name string, stateLoc string, opts ...ReadURLOption) template.FuncMap

MustFuncMapWithName is similar to FuncMapWithName, but panics if it cannot get and parse tfstate.

Types

type Object added in v0.0.2

type Object struct {
	Value any
}

func (*Object) Bytes added in v0.0.8

func (a *Object) Bytes() []byte

func (*Object) MarshalJSON added in v1.4.0

func (a *Object) MarshalJSON() ([]byte, error)

func (*Object) Query added in v0.0.2

func (a *Object) Query(query string) (*Object, error)

Query queries object by go-jq

func (*Object) String added in v0.0.2

func (a *Object) String() string

type ReadURLOption added in v1.9.0

type ReadURLOption interface {
	// contains filtered or unexported methods
}

ReadURLOption is an interface for options passed to ReadURL

type S3EndpointOption added in v1.9.0

type S3EndpointOption string

S3EndpointOption specifies the S3 endpoint URL

type S3Option added in v1.5.0

type S3Option struct {
	AccessKey string
	SecretKey string
	Region    string
	RoleArn   string
	Endpoint  string
}

type TFState

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

TFState represents a tfstate

func Empty added in v1.12.0

func Empty() *TFState

Empty returns a TFState with no underlying tfstate source. Useful when the caller wants to populate the state entirely via SetOverrides — e.g. an orchestrator that already has all relevant resource values in hand and does not want a tfstate file as a source.

A TFState returned by Empty satisfies the same interface as one returned by Read / ReadFile / ReadURL; Lookup, FuncMap, Dump, and List all work and simply return empty/miss until SetOverrides is called.

func Read

func Read(ctx context.Context, src io.Reader) (*TFState, error)

Read reads a tfstate from io.Reader

func ReadFile added in v0.0.3

func ReadFile(ctx context.Context, file string) (*TFState, error)

ReadFile reads terraform.tfstate from the file (Firstly, a workspace reads TF_WORKSPACE environment variable. if it doesn't exist, it reads from environment file in the same directory)

func ReadURL added in v0.1.0

func ReadURL(ctx context.Context, loc string, opts ...ReadURLOption) (*TFState, error)

ReadURL reads terraform.tfstate from the URL.

func ReadWithWorkspace added in v0.0.3

func ReadWithWorkspace(ctx context.Context, src io.Reader, ws string) (*TFState, error)

ReadWithWorkspace reads a tfstate from io.Reader with workspace

func (*TFState) DiscardScannedState added in v1.12.1

func (s *TFState) DiscardScannedState()

DiscardScannedState drops anything that has already been scanned from the underlying tfstate (path / url / io.Reader) and prevents any future lazy scan from populating it. After this call, Lookup resolves keys from the override map only: a key that is absent from overrides surfaces as a miss, the same as on a freshly Empty() state.

This is the right knob for callers that supply every relevant value through SetOverrides — e.g. a Terraform provider wrapping ecspresso — and want missing overrides to fail fast instead of being silently filled in from a possibly-stale tfstate file.

One-shot operation: the scanned data is freed and cannot be brought back without re-Read'ing the state.

func (*TFState) Dump added in v1.4.0

func (s *TFState) Dump() (map[string]*Object, error)

Dump dumps all resources, outputs, and data sources in tfstate

func (*TFState) FuncMap added in v1.3.2

func (s *TFState) FuncMap(ctx context.Context) template.FuncMap

func (*TFState) FuncMapWithName added in v1.3.2

func (s *TFState) FuncMapWithName(ctx context.Context, name string) template.FuncMap

func (*TFState) JsonnetNativeFuncs added in v1.3.2

func (s *TFState) JsonnetNativeFuncs(ctx context.Context) []*jsonnet.NativeFunction

TFState provides a tfstate.

func (*TFState) JsonnetNativeFuncsWithPrefix added in v1.3.2

func (s *TFState) JsonnetNativeFuncsWithPrefix(ctx context.Context, prefix string) []*jsonnet.NativeFunction

JsonnetNativeFuncsWithPrefix provides the native functions for go-jsonnet with prefix.

func (*TFState) List added in v0.0.5

func (s *TFState) List() ([]string, error)

List lists resource and output names in tfstate

func (*TFState) Lookup

func (s *TFState) Lookup(key string) (*Object, error)

Lookup lookups attributes of the specified key in tfstate

func (*TFState) SetOverrides added in v1.12.0

func (s *TFState) SetOverrides(overrides map[string]any)

SetOverrides replaces this state's override map. Each key is a resource-level address (`aws_foo.bar`, `output.foo`, `module.m.aws_foo.bar[0]`) — i.e. an address at the same granularity as the entries the scanner produces from a real tfstate file. The value is the resource's full attributes (typically map[string]any), or for outputs the output value itself.

Lookup consults overrides at both the exact-match and longest-prefix stages: a request for `aws_foo.bar.value` finds the `aws_foo.bar` override and navigates `.value` via the same jq path the underlying state uses. Overrides win over the underlying state on both kinds of match.

Pass nil or an empty map to clear. SetOverrides is safe to call concurrently with Lookup.

Jump to

Keyboard shortcuts

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