Documentation ¶
Overview ¶
Package varcontext works out the values for Terraform variables
Index ¶
- Constants
- type ContextBuilder
- func (builder *ContextBuilder) Build() (*VarContext, error)
- func (builder *ContextBuilder) BuildMap() (map[string]any, error)
- func (builder *ContextBuilder) MergeDefaultWithEval(brokerVariables []DefaultVariable) *ContextBuilder
- func (builder *ContextBuilder) MergeEvalResult(key, template, resultType string) *ContextBuilder
- func (builder *ContextBuilder) MergeJSONObject(data json.RawMessage) *ContextBuilder
- func (builder *ContextBuilder) MergeMap(data map[string]any) *ContextBuilder
- func (builder *ContextBuilder) MergeStruct(data any) *ContextBuilder
- func (builder *ContextBuilder) SetEvalConstants(constants map[string]any) *ContextBuilder
- type DefaultVariable
- type VarContext
- func (vc *VarContext) Error() error
- func (vc *VarContext) GetBool(key string) (res bool)
- func (vc *VarContext) GetInt(key string) (res int)
- func (vc *VarContext) GetString(key string) (res string)
- func (vc *VarContext) GetStringMapString(key string) (res map[string]string)
- func (vc *VarContext) HasKey(key string) bool
- func (vc *VarContext) ToJSON() (json.RawMessage, error)
- func (vc *VarContext) ToMap() map[string]any
Examples ¶
Constants ¶
const ( TypeObject = "object" TypeBoolean = "boolean" TypeArray = "array" TypeNumber = "number" TypeString = "string" TypeInteger = "integer" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextBuilder ¶
type ContextBuilder struct {
// contains filtered or unexported fields
}
ContextBuilder is a builder for VariableContexts.
func Builder ¶
func Builder() *ContextBuilder
Builder creates a new ContextBuilder for constructing VariableContexts.
func (*ContextBuilder) Build ¶
func (builder *ContextBuilder) Build() (*VarContext, error)
Build generates a finalized VarContext based on the state of the builder. Exactly one of VarContext and error will be nil.
func (*ContextBuilder) BuildMap ¶
func (builder *ContextBuilder) BuildMap() (map[string]any, error)
BuildMap is a shorthand of calling build then turning the returned varcontext into a map. Exactly one of map and error will be nil.
Example ¶
_, e := Builder().MergeEvalResult("a", "${assert(false, \"failure!\")}", "string").BuildMap() fmt.Printf("Error: %v\n", e) m, _ := Builder().MergeEvalResult("a", "${1+1}", "string").BuildMap() fmt.Printf("Map: %v\n", m)
Output: Error: 1 error(s) occurred: couldn't compute the value for "a", template: "${assert(false, \"failure!\")}", assert: assertion failed: failure! Map: map[a:2]
func (*ContextBuilder) MergeDefaultWithEval ¶ added in v0.11.0
func (builder *ContextBuilder) MergeDefaultWithEval(brokerVariables []DefaultVariable) *ContextBuilder
MergeDefaultWithEval gets the default values from the given BrokerVariables and if they're a string, it tries to evaluate it in the built up context.
func (*ContextBuilder) MergeEvalResult ¶
func (builder *ContextBuilder) MergeEvalResult(key, template, resultType string) *ContextBuilder
MergeEvalResult evaluates the template against the templating engine and merges in the value if the result is not an error.
func (*ContextBuilder) MergeJSONObject ¶ added in v0.10.1
func (builder *ContextBuilder) MergeJSONObject(data json.RawMessage) *ContextBuilder
MergeJSONObject converts the raw message to a map[string]any and merges the values into the context. Blank RawMessages are treated like empty objects.
func (*ContextBuilder) MergeMap ¶
func (builder *ContextBuilder) MergeMap(data map[string]any) *ContextBuilder
MergeMap inserts all the keys and values from the map into the context.
func (*ContextBuilder) MergeStruct ¶
func (builder *ContextBuilder) MergeStruct(data any) *ContextBuilder
MergeStruct merges the given struct using its JSON field names.
func (*ContextBuilder) SetEvalConstants ¶
func (builder *ContextBuilder) SetEvalConstants(constants map[string]any) *ContextBuilder
SetEvalConstants sets constants that will be available to evaluation contexts but not in the final output produced by the Build() call. These can be used to set values users can't overwrite mistakenly or maliciously.
type DefaultVariable ¶
type DefaultVariable struct { Name string `json:"name" yaml:"name"` Default any `json:"default" yaml:"default"` Overwrite bool `json:"overwrite" yaml:"overwrite"` Type string `json:"type" yaml:"type"` }
DefaultVariable holds a value that may or may not be evaluated. If the value is a string then it will be evaluated.
func (*DefaultVariable) Validate ¶
func (dv *DefaultVariable) Validate() (errs *validation.FieldError)
Validate implements validation.Validatable.
type VarContext ¶
type VarContext struct {
// contains filtered or unexported fields
}
func (*VarContext) Error ¶
func (vc *VarContext) Error() error
Error gets the accumulated error(s) that this VarContext holds.
func (*VarContext) GetBool ¶
func (vc *VarContext) GetBool(key string) (res bool)
GetBool gets a boolean from the context, storing an error if the key doesn't exist or the variable couldn't be converted to a bool. Integers can behave like bools in C style, 0 is false. The strings "true" and "false" are also cast to their bool values.
func (*VarContext) GetInt ¶
func (vc *VarContext) GetInt(key string) (res int)
GetInt gets an integer from the context, storing an error if the key doesn't exist or the variable couldn't be converted to an int.
func (*VarContext) GetString ¶
func (vc *VarContext) GetString(key string) (res string)
GetString gets a string from the context, storing an error if the key doesn't exist or the variable couldn't be converted to a string.
func (*VarContext) GetStringMapString ¶
func (vc *VarContext) GetStringMapString(key string) (res map[string]string)
GetStringMapString gets map[string]string from the context, storing an error if the key doesn't exist or the variable couldn't be cast.
func (*VarContext) HasKey ¶
func (vc *VarContext) HasKey(key string) bool
func (*VarContext) ToJSON ¶ added in v0.10.1
func (vc *VarContext) ToJSON() (json.RawMessage, error)
ToJSON gets the underlying JSON representation of the variable context.
func (*VarContext) ToMap ¶
func (vc *VarContext) ToMap() map[string]any
ToMap gets the underlying map representation of the variable context.
Directories ¶
Path | Synopsis |
---|---|
Package interpolation exposes the HIL (Hashicorp Interpolation Language)
|
Package interpolation exposes the HIL (Hashicorp Interpolation Language) |