variables

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInputVariables

func AddInputVariables(ctx *hcl.EvalContext, vs Values)

AddInputVariables adds the InputValues to the provided hcl context

func DecodeVariableBlocks

func DecodeVariableBlocks(
	ctx *hcl.EvalContext,
	content *hcl.BodyContent,
) (map[string]*Variable, hcl.Diagnostics)

DecodeVariableBlocks uses the hclConfig schema to iterate over all variable blocks, validating names and types and checking for duplicates. It returns the final map of Variables to store for later reference.

func LoadAutoFiles

func LoadAutoFiles(wd string) ([]*pb.Variable, hcl.Diagnostics)

LoadAutoFiles loads any *.auto.wpvars(.json) files in the source repo

func LoadDynamicDefaults added in v0.7.0

func LoadDynamicDefaults(
	ctx context.Context,
	log hclog.Logger,
	pbvars []*pb.Variable,
	cfgSrcs []*pb.ConfigSource,
	vars map[string]*Variable,
	dynamicOpts ...appconfig.Option,
) ([]*pb.Variable, hcl.Diagnostics)

LoadDynamicDefaults will load the default values for variables that have dynamic configurations. This will only load the values if there isn't an existing variable set in pbvars. Therefore, it is recommended that this is called last and the values are _prepended_ to pbvars for priority.

func LoadEnvValues added in v0.6.0

func LoadEnvValues(vars map[string]*Variable) ([]*pb.Variable, hcl.Diagnostics)

LoadEnvValues loads the variable values from environment variables specified via the `env` field on the `variable` stanza.

func LoadVariableValues

func LoadVariableValues(vars map[string]string, files []string) ([]*pb.Variable, hcl.Diagnostics)

LoadVariableValues collects values set via the CLI (-var, -varfile) and local env vars (WP_VAR_*) and translates those values to pb.Variables. These pb.Variables can then be set on the job for eventual parsing on the runner, after the runner has decoded the variables defined in the waypoint.hcl. All values are set as protobuf strings, with the expectation that later evaluation will convert them to their defined types.

func NeedsDynamicDefaults added in v0.7.0

func NeedsDynamicDefaults(
	pbvars []*pb.Variable,
	vars map[string]*Variable,
) bool

NeedsDynamicDefaults returns true if there are variables with a dynamic default value set that must be evaluated (because the value is not overridden).

Types

type HclVariable

type HclVariable struct {
	Name        string         `hcl:",label"`
	Default     hcl.Expression `hcl:"default,optional"`
	Type        hcl.Expression `hcl:"type,optional"`
	Description string         `hcl:"description,optional"`
	Env         []string       `hcl:"env,optional"`
	Sensitive   bool           `hcl:"sensitive,optional"`
}

HclVariable is used when decoding the waypoint.hcl config. Because we use hclsimple for this decode, we need the `Type` to be evaluated as an hcl expression. When we parse the config, we need `Type` to be evaluated as cty.Type, so this struct is only used for the basic decoding of the file to verify HCL syntax.

type Value

type Value struct {
	Value  cty.Value
	Source string
	Expr   hcl.Expression
	// The location of the variable value if the value was provided from a file
	Range hcl.Range
}

Value contain the value of the variable along with associated metadata, including the source it was set from: cli, file, env, vcs, server/ui

type Values

type Values map[string]*Value

Values are used to store values collected from various sources. Values are added to the map in precedence order, and then used to create the final map of cty.Values for config hcl context evaluation.

func EvaluateVariables

func EvaluateVariables(
	log hclog.Logger,
	pbvars []*pb.Variable,
	vs map[string]*Variable,
	salt string,
) (Values, map[string]*pb.Variable_FinalValue, hcl.Diagnostics)

EvaluateVariables evaluates the provided variable values and validates their types per the type declared in the waypoint.hcl for that variable name. The order in which values are evaluated corresponds to their precedence, with higher precedence values overwriting lower precedence values.

The supplied map of *Variable should be all defined variables (currently comes from decoding all variable blocks within the waypoint.hcl), and is used to validate types and that all variables have at least one assigned value.

type Variable

type Variable struct {
	Name string

	// The default value in the variable definition
	Default *Value

	// A list of environment variables that will be sourced to satisfy
	// the value of this variable.
	Env []string

	// Cty Type of the variable. If the default value or a collected value is
	// not of this type nor can be converted to this type an error diagnostic
	// will show up. This allows us to assume that values are valid.
	//
	// When a default value - and no type - is passed into the variable
	// declaration, the type of the default variable will be used.
	Type cty.Type

	// Variables with this set will be hashed as SHA256 values for
	// the purposes of output and logging
	Sensitive bool

	// Description of the variable
	Description string

	// The location of the variable definition block in the waypoint.hcl
	Range hcl.Range
}

Variable stores a parsed variable definition from the waypoint.hcl

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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