blocktoattr

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package blocktoattr includes some helper functions that can perform preprocessing on a HCL body where a configschema.Block schema is available in order to allow list and set attributes defined in the schema to be optionally written by the user as block syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandedFunctions added in v1.7.0

func ExpandedFunctions(body hcl.Body, schema *configschema.Block) []hcl.Traversal

ExpandedFunctions finds all of the global functions referenced in the given body with the given schema while taking into account the possibilities both of "dynamic" blocks being expanded and the possibility of certain attributes being written instead as nested blocks as allowed by the FixUpBlockAttrs function.

This function exists to allow functions to be analyzed prior to dynamic block expansion while also dealing with the fact that dynamic block expansion might in turn produce nested blocks that are subject to FixUpBlockAttrs.

This is intended as a drop-in replacement for dynblock.FunctionsHCLDec, which is itself a drop-in replacement for hcldec.Functions.

func ExpandedVariables

func ExpandedVariables(body hcl.Body, schema *configschema.Block) []hcl.Traversal

ExpandedVariables finds all of the global variables referenced in the given body with the given schema while taking into account the possibilities both of "dynamic" blocks being expanded and the possibility of certain attributes being written instead as nested blocks as allowed by the FixUpBlockAttrs function.

This function exists to allow variables to be analyzed prior to dynamic block expansion while also dealing with the fact that dynamic block expansion might in turn produce nested blocks that are subject to FixUpBlockAttrs.

This is intended as a drop-in replacement for dynblock.VariablesHCLDec, which is itself a drop-in replacement for hcldec.Variables.

func FixUpBlockAttrs

func FixUpBlockAttrs(body hcl.Body, schema *configschema.Block) hcl.Body

FixUpBlockAttrs takes a raw HCL body and adds some additional normalization functionality to allow attributes that are specified as having list or set type in the schema to be written with HCL block syntax as multiple nested blocks with the attribute name as the block type.

The fixup is only applied in the absence of structural attribute types. The presence of these types indicate the use of a provider which does not support mapping blocks to attributes.

This partially restores some of the block/attribute confusion from HCL 1 so that existing patterns that depended on that confusion can continue to be used in the short term while we settle on a longer-term strategy.

Most of the fixup work is actually done when the returned body is subsequently decoded, so while FixUpBlockAttrs always succeeds, the eventual decode of the body might not, if the content of the body is so ambiguous that there's no safe way to map it to the schema.

func SchemaForCtyContainerType

func SchemaForCtyContainerType(ty cty.Type) *configschema.NestedBlock

SchemaForCtyContainerType converts a cty list-of-object or set-of-object type into an approximately-equivalent configschema.NestedBlock. If the given type is not of the expected kind then this function will panic.

func SchemaForCtyElementType

func SchemaForCtyElementType(ty cty.Type) *configschema.Block

SchemaForCtyElementType converts a cty object type into an approximately-equivalent configschema.Block representing the element of a list or set. If the given type is not an object type then this function will panic.

func TypeCanBeBlocks

func TypeCanBeBlocks(ty cty.Type) bool

TypeCanBeBlocks returns true if the given type is a list-of-object or set-of-object type, and would thus be subject to the blocktoattr fixup if used as an attribute type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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