Documentation ¶
Overview ¶
Package typeexpr extends HCL with a convention for describing HCL types within configuration files.
The type syntax is processed statically from a hcl.Expression, so it cannot use any of the usual language operators. This is similar to type expressions in statically-typed programming languages.
variable "example" { type = list(string) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConvertFunc function.Function
ConvertFunc is a cty function that implements type conversions.
Its signature is as follows:
convert(value, type_constraint)
...where type_constraint is a type constraint expression as defined by typeexpr.TypeConstraint.
It relies on HCL's customdecode extension and so it's not suitable for use in non-HCL contexts or if you are using a HCL syntax implementation that does not support customdecode for function arguments. However, it _is_ supported for function calls in the HCL native expression syntax.
var TypeConstraintType cty.Type
TypeConstraintType is a cty capsule type that allows cty type constraints to be used as values.
If TypeConstraintType is used in a context supporting the customdecode.CustomExpressionDecoder extension then it will implement expression decoding using the TypeConstraint function, thus allowing type expressions to be used in contexts where value expressions might normally be expected, such as in arguments to function calls.
Functions ¶
func Type ¶
Type attempts to process the given expression as a type expression and, if successful, returns the resulting type. If unsuccessful, error diagnostics are returned.
func TypeConstraint ¶
TypeConstraint attempts to parse the given expression as a type constraint and, if successful, returns the resulting type. If unsuccessful, error diagnostics are returned.
A type constraint has the same structure as a type, but it additionally allows the keyword "any" to represent cty.DynamicPseudoType, which is often used as a wildcard in type checking and type conversion operations.
func TypeConstraintFromVal ¶
TypeConstraintFromVal extracts the type from a cty.Value of TypeConstraintType that was previously constructed using TypeConstraintVal.
If the given value isn't a known, non-null value of TypeConstraintType then this function will panic.
func TypeConstraintVal ¶
TypeConstraintVal constructs a cty.Value whose type is TypeConstraintType.
func TypeString ¶
TypeString returns a string rendering of the given type as it would be expected to appear in the HCL native syntax.
This is primarily intended for showing types to the user in an application that uses typexpr, where the user can be assumed to be familiar with the type expression syntax. In applications that do not use typeexpr these results may be confusing to the user and so type.FriendlyName may be preferable, even though it's less precise.
TypeString produces reasonable results only for types like what would be produced by the Type and TypeConstraint functions. In particular, it cannot support capsule types.
Types ¶
This section is empty.