typeexpr

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0, MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package typeexpr is a fork of github.com/hashicorp/hcl/v2/ext/typeexpr which has additional experimental support for optional attributes.

This is here as part of the module_variable_optional_attrs experiment. If that experiment is successful, the changes here may be upstreamed into HCL itself or, if we deem it to be Terraform-specific, we should at least update this documentation to reflect that this is now the primary Terraform-specific type expression implementation, separate from the upstream HCL one.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func Type(expr hcl.Expression) (cty.Type, hcl.Diagnostics)

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

func TypeConstraint(expr hcl.Expression) (cty.Type, hcl.Diagnostics)

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

func TypeConstraintFromVal(v cty.Value) cty.Type

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

func TypeConstraintVal(ty cty.Type) cty.Value

TypeConstraintVal constructs a cty.Value whose type is TypeConstraintType.

func TypeString

func TypeString(ty cty.Type) string

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.

Jump to

Keyboard shortcuts

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