binding

package
v0.14.43 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// must match the data source names, see DataSourcesMap in observe/provider.go
	KindDataset         = addKind("dataset")
	KindWorksheet       = addKind("worksheet")
	KindWorkspace       = addKind("workspace")
	KindUser            = addKind("user")
	KindDashboard       = addKind("dashboard")
	KindMonitorV2       = addKind("monitor_v2")
	KindMonitorV2Action = addKind("monitor_v2_action")
	KindMonitor         = addKind("monitor")
)

Functions

This section is empty.

Types

type BindingsObject

type BindingsObject struct {
	Mappings      Mapping `json:"mappings"`
	Kinds         []Kind  `json:"kinds"`
	Workspace     Target  `json:"workspace"`
	WorkspaceName string  `json:"workspace_name"`
}

BindingsObject contains all the information necessary to generate terraform data sources and local variable definitions to support the local variable references replacing the raw ids in the resource data.

type Generator

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

func NewGenerator

func NewGenerator(ctx context.Context, resourceType Kind, resourceName string,
	client *observe.Client, enabledBindings KindSet) (Generator, error)

NewGenerator creates a new binding generator for the given resource type and name, which keeps track of all the bindings generated for raw ids found through later calls to Generate and TryBind.

func (*Generator) Generate

func (g *Generator) Generate(data interface{})

Generate walks the provided data structure and for all ids encountered, generates a binding for it, and replaces the id with a local variable reference

func (*Generator) GenerateJson

func (g *Generator) GenerateJson(jsonStr []byte) ([]byte, error)

GenerateJson does the same as Generate, but accepts a raw json string

func (*Generator) GetBindings added in v0.14.35

func (g *Generator) GetBindings() (BindingsObject, error)

GetBindings returns the bindings generated so far

func (*Generator) GetBindingsJson added in v0.14.35

func (g *Generator) GetBindingsJson() ([]byte, error)

func (*Generator) InsertBindingsObject

func (g *Generator) InsertBindingsObject(data map[string]interface{}) error

InsertBindingsObject inserts the bindings object into the provided map

func (*Generator) InsertBindingsObjectJson

func (g *Generator) InsertBindingsObjectJson(jsonData []byte) ([]byte, error)

InsertBindingsObjectJson inserts the bindings object into the provided json data, root must be a map

func (*Generator) TryBindId added in v0.14.35

func (g *Generator) TryBindId(kind Kind, id string) (maybeRef string, didBind bool)

lookup by kind and id, if valid then return a local variable reference, otherwise return the id (no-op)

func (*Generator) TryBindOid added in v0.14.35

func (g *Generator) TryBindOid(oidObj oid.OID) (maybeRef string, didBind bool)

infer the kind from the oid and lookup, if valid then return a local variable reference, otherwise return the oid as a string (no-op)

type Kind

type Kind string

type KindSet

type KindSet map[Kind]struct{}

func NewKindSet

func NewKindSet(kinds ...Kind) KindSet

type Mapping

type Mapping map[Ref]Target

A binding, i.e. mapping of resource kind + label -> terraform local variable name (which the ids have been replaced with)

func NewMapping

func NewMapping() Mapping

type Ref

type Ref struct {
	Kind Kind
	Key  string // id when used in ResourceCache, label when used in Mapping
}

func NewRefFromString

func NewRefFromString(s string) (Ref, bool)

func (Ref) MarshalText

func (r Ref) MarshalText() (text []byte, err error)

func (*Ref) String

func (r *Ref) String() string

func (*Ref) UnmarshalText

func (r *Ref) UnmarshalText(text []byte) error

type ResourceCache

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

func NewResourceCache

func NewResourceCache(ctx context.Context, kinds KindSet, client *observe.Client, forResourceKind Kind, forResourceName string) (ResourceCache, error)

NewResourceCache loads all resources of the given kinds and creates a cache of id -> label mappings

func (*ResourceCache) LookupId

func (c *ResourceCache) LookupId(kind Kind, id string) *ResourceCacheEntry

type ResourceCacheEntry

type ResourceCacheEntry struct {
	TfName string
	Label  string
}

type Target

type Target struct {
	// Name of the local variable that will be generated for this target, used in place of the raw ids
	TfLocalBindingVar string `json:"tf_local_binding_var"`
	// Name of the terraform data source that will be generated for this target
	TfName string `json:"tf_name"`
	// When generating locals, used to determine whether we should do ${data_source}.id or ${data_source}.oid
	IsOid bool `json:"is_oid"`
}

Jump to

Keyboard shortcuts

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