Documentation
¶
Index ¶
- Constants
- func FuncMap(ctx context.Context, stateLoc string, opts ...ReadURLOption) (template.FuncMap, error)
- func FuncMapWithName(ctx context.Context, name string, stateLoc string, opts ...ReadURLOption) (template.FuncMap, error)
- func JsonnetNativeFuncs(ctx context.Context, prefix, stateLoc string, opts ...ReadURLOption) ([]*jsonnet.NativeFunction, error)
- func MustFuncMap(ctx context.Context, stateLoc string, opts ...ReadURLOption) template.FuncMap
- func MustFuncMapWithName(ctx context.Context, name string, stateLoc string, opts ...ReadURLOption) template.FuncMap
- type Object
- type ReadURLOption
- type S3EndpointOption
- type S3Option
- type TFState
- func Empty() *TFState
- func Read(ctx context.Context, src io.Reader) (*TFState, error)
- func ReadFile(ctx context.Context, file string) (*TFState, error)
- func ReadURL(ctx context.Context, loc string, opts ...ReadURLOption) (*TFState, error)
- func ReadWithWorkspace(ctx context.Context, src io.Reader, ws string) (*TFState, error)
- func (s *TFState) DiscardScannedState()
- func (s *TFState) Dump() (map[string]*Object, error)
- func (s *TFState) FuncMap(ctx context.Context) template.FuncMap
- func (s *TFState) FuncMapWithName(ctx context.Context, name string) template.FuncMap
- func (s *TFState) JsonnetNativeFuncs(ctx context.Context) []*jsonnet.NativeFunction
- func (s *TFState) JsonnetNativeFuncsWithPrefix(ctx context.Context, prefix string) []*jsonnet.NativeFunction
- func (s *TFState) List() ([]string, error)
- func (s *TFState) Lookup(key string) (*Object, error)
- func (s *TFState) SetOverrides(overrides map[string]any)
Constants ¶
const S3EndpointEnvKey = "AWS_ENDPOINT_URL_S3"
const (
StateVersion = 4
)
Variables ¶
This section is empty.
Functions ¶
func FuncMap ¶ added in v0.0.12
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
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) MarshalJSON ¶ added in v1.4.0
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 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 ReadFile ¶ added in v0.0.3
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 ReadWithWorkspace ¶ added in v0.0.3
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
Dump dumps all resources, outputs, and data sources in tfstate
func (*TFState) FuncMapWithName ¶ added in v1.3.2
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) SetOverrides ¶ added in v1.12.0
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.