hcl2shim

package
v0.12.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66"

UnknownVariableValue is a sentinel value that can be used to denote that the value of a variable is unknown at this time. RawConfig uses this information to build up data about unknown keys.

Variables

This section is empty.

Functions

func ConfigValueFromHCL2

func ConfigValueFromHCL2(v cty.Value) interface{}

ConfigValueFromHCL2 converts a value from HCL2 (really, from the cty dynamic types library that HCL2 uses) to a value type that matches what would've been produced from the HCL-based interpolator for an equivalent structure.

This function will transform a cty null value into a Go nil value, which isn't a possible outcome of the HCL/HIL-based decoder and so callers may need to detect and reject any null values.

func ConfigValueFromHCL2Block added in v0.12.0

func ConfigValueFromHCL2Block(v cty.Value, schema *configschema.Block) map[string]interface{}

ConfigValueFromHCL2Block is like ConfigValueFromHCL2 but it works only for known object values and uses the provided block schema to perform some additional normalization to better mimic the shape of value that the old HCL1/HIL-based codepaths would've produced.

In particular, it discards the collections that we use to represent nested blocks (other than NestingSingle) if they are empty, which better mimics the HCL1 behavior because HCL1 had no knowledge of the schema and so didn't know that an unspecified block _could_ exist.

The given object value must conform to the schema's implied type or this function will panic or produce incorrect results.

This is primarily useful for the final transition from new-style values to terraform.ResourceConfig before calling to a legacy provider, since helper/schema (the old provider SDK) is particularly sensitive to these subtle differences within its validation code.

func FlatmapValueFromHCL2 added in v0.12.0

func FlatmapValueFromHCL2(v cty.Value) map[string]string

FlatmapValueFromHCL2 converts a value from HCL2 (really, from the cty dynamic types library that HCL2 uses) to a map compatible with what would be produced by the "flatmap" package.

The type of the given value informs the structure of the resulting map. The value must be of an object type or this function will panic.

Flatmap values can only represent maps when they are of primitive types, so the given value must not have any maps of complex types or the result is undefined.

func HCL2TypeForHILType

func HCL2TypeForHILType(hilType ast.Type) cty.Type

func HCL2ValueFromConfigValue

func HCL2ValueFromConfigValue(v interface{}) cty.Value

HCL2ValueFromConfigValue is the opposite of configValueFromHCL2: it takes a value as would be returned from the old interpolator and turns it into a cty.Value so it can be used within, for example, an HCL2 EvalContext.

func HCL2ValueFromFlatmap added in v0.12.0

func HCL2ValueFromFlatmap(m map[string]string, ty cty.Type) (cty.Value, error)

HCL2ValueFromFlatmap converts a map compatible with what would be produced by the "flatmap" package to a HCL2 (really, the cty dynamic types library that HCL2 uses) object type.

The intended result type must be provided in order to guide how the map contents are decoded. This must be an object type or this function will panic.

Flatmap values can only represent maps when they are of primitive types, so the given type must not have any maps of complex types or the result is undefined.

The result may contain null values if the given map does not contain keys for all of the different key paths implied by the given type.

func HCL2ValueFromHILVariable

func HCL2ValueFromHILVariable(v ast.Variable) cty.Value

func HILVariableFromHCL2Value

func HILVariableFromHCL2Value(v cty.Value) ast.Variable

func RequiresReplace added in v0.12.0

func RequiresReplace(attrs []string, ty cty.Type) ([]cty.Path, error)

RequiresReplace takes a list of flatmapped paths from a InstanceDiff.Attributes along with the corresponding cty.Type, and returns the list of the cty.Paths that are flagged as causing the resource replacement (RequiresNew). This will filter out redundant paths, paths that refer to flatmapped indexes (e.g. "#", "%"), and will return any changes within a set as the path to the set itself.

Types

type SingleAttrBody

type SingleAttrBody struct {
	Name string
	Expr hcl2.Expression
}

SingleAttrBody is a weird implementation of hcl2.Body that acts as if it has a single attribute whose value is the given expression.

This is used to shim Resource.RawCount and Output.RawConfig to behave more like they do in the old HCL loader.

func (SingleAttrBody) Content

func (SingleAttrBody) JustAttributes

func (b SingleAttrBody) JustAttributes() (hcl2.Attributes, hcl2.Diagnostics)

func (SingleAttrBody) MissingItemRange

func (b SingleAttrBody) MissingItemRange() hcl2.Range

func (SingleAttrBody) PartialContent

func (b SingleAttrBody) PartialContent(schema *hcl2.BodySchema) (*hcl2.BodyContent, hcl2.Body, hcl2.Diagnostics)

Jump to

Keyboard shortcuts

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