hclhelpers

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: AGPL-3.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttributeToBool

func AttributeToBool(attr *hcl.Attribute, evalContext *hcl.EvalContext, allowExpression bool) (*bool, hcl.Diagnostics)

func AttributeToInt

func AttributeToInt(attr *hcl.Attribute, evalContext *hcl.EvalContext, allowExpression bool) (*int64, hcl.Diagnostics)

func AttributeToMap

func AttributeToMap(attr *hcl.Attribute, evalContext *hcl.EvalContext, allowExpression bool) (map[string]interface{}, hcl.Diagnostics)

func AttributeToString

func AttributeToString(attr *hcl.Attribute, evalContext *hcl.EvalContext, allowExpression bool) (*string, hcl.Diagnostics)

func BlockRange

func BlockRange(block *hcl.Block) hcl.Range

func BlockRangePointer

func BlockRangePointer(block *hcl.Block) *hcl.Range

func BlocksToMap

func BlocksToMap(blocks hcl.Blocks) map[string]*hcl.Block

BlocksToMap convert an array of blocks to a map keyed by block laabel NOTE: this panics if any blocks do not have a label

func CoerceStringToGoBasedOnCtyType

func CoerceStringToGoBasedOnCtyType(input string, typ cty.Type) (interface{}, error)

func ConvertInterfaceToCtyValue

func ConvertInterfaceToCtyValue(v interface{}) (cty.Value, error)

func ConvertMapInterfaceToCtyValue

func ConvertMapInterfaceToCtyValue(v interface{}) (cty.Value, error)

func ConvertMapOrSliceToCtyValue

func ConvertMapOrSliceToCtyValue(data interface{}) (cty.Value, error)

func ConvertMapToCtyValue

func ConvertMapToCtyValue[K comparable, V any](v map[K]V) (cty.Value, error)

func ConvertSliceToCtyValue

func ConvertSliceToCtyValue[T SliceTypeConstraint](v T) (cty.Value, error)

ConvertSliceToCtyValue converts a slice of various types to cty.Value

func CtyToGo

func CtyToGo(v cty.Value) (val interface{}, err error)

func CtyToGoBoolSlice

func CtyToGoBoolSlice(v cty.Value, typ cty.Type) (val []bool, err error)

func CtyToGoInterfaceSlice

func CtyToGoInterfaceSlice(v cty.Value) (val []interface{}, err error)

func CtyToGoMapBool

func CtyToGoMapBool(v cty.Value) (map[string]bool, error)

func CtyToGoMapInterface

func CtyToGoMapInterface(v cty.Value) (map[string]interface{}, error)

func CtyToGoMapNumeric

func CtyToGoMapNumeric(v cty.Value) (map[string]float64, error)

func CtyToGoMapString

func CtyToGoMapString(v cty.Value) (map[string]string, error)

func CtyToGoNumericSlice

func CtyToGoNumericSlice(v cty.Value, typ cty.Type) (val []float64, err error)

func CtyToGoStringSlice

func CtyToGoStringSlice(v cty.Value, typ cty.Type) (val []string, err error)

func CtyToInt64

func CtyToInt64(val cty.Value) (*int64, hcl.Diagnostics)

func CtyToJSON

func CtyToJSON(val cty.Value) (string, error)

CtyToJSON converts a cty value to it;s JSON representation

func CtyToPostgresString

func CtyToPostgresString(v cty.Value) (valStr string, err error)

CtyToPostgresString convert a cty value into a postgres representation of the value

func CtyToString

func CtyToString(v cty.Value) (valStr string, err error)

CtyToString convert a cty value into a string representation of the value

func CtyTupleToArrayOfStrings

func CtyTupleToArrayOfStrings(val cty.Value) ([]string, error)

func CtyTypeToHclType

func CtyTypeToHclType(types ...cty.Type) string

CtyTypeToHclType converts a cty type to a hcl type accept multiple types and use the first non null and non dynamic one

func ExpressionToDepends

func ExpressionToDepends(expr hcl.Expression, validDependsOnTypes []string) ([]string, hcl.Diagnostics)

func ExpressionsEqual

func ExpressionsEqual(expr1, expr2 hcl.Expression) bool

func FindChildBlocks

func FindChildBlocks(parentBlock *hcl.Block, blockType string) hcl.Blocks

func FindFirstChildBlock

func FindFirstChildBlock(parentBlock *hcl.Block, blockType string) *hcl.Block

func GetFirstBlockOfType

func GetFirstBlockOfType(blocks hcl.Blocks, blockType string) *hcl.Block

func GoToHCLString added in v1.5.0

func GoToHCLString(data interface{}) (string, error)

GoToHCLString converts a Go data structure to an HCL string.

func GoToPostgresString

func GoToPostgresString(v any) (string, error)

GoToPostgresString convert a go value into a postgres representation of the value

func GoTypeMatchesCtyType

func GoTypeMatchesCtyType(val interface{}, ctyType cty.Type) bool

func HclBodyToHclString

func HclBodyToHclString(body hcl.Body, excludeContent *hcl.BodyContent) (string, hcl.Diagnostics)

HclBodyToHclString builds a hcl string with all attributes in the connection config which are NOT specified in the coneciton block schema this is passed to the plugin who will validate and parse it

func HclSyntaxBlockRangePointer

func HclSyntaxBlockRangePointer(block *hclsyntax.Block) *hcl.Range

func IsValueCompatibleWithType added in v0.3.0

func IsValueCompatibleWithType(ctyType cty.Type, value cty.Value) bool

func JSONToHcl

func JSONToHcl(jsonString string) (string, hcl.Diagnostics)

func QuotePostgresBytes

func QuotePostgresBytes(buf []byte) string

QuotePostgresBytes taken from github.com/jackc/pgx/v5@v4.17.2/internal/sanitize/sanitize.go

func QuotePostgresString

func QuotePostgresString(str string) string

QuotePostgresString taken from github.com/jackc/pgx/v5@v4.17.2/internal/sanitize/sanitize.go

func ResourceNameFromTraversal

func ResourceNameFromTraversal(resourceType string, traversal hcl.Traversal) (string, bool)

ResourceNameFromTraversal converts a traversal to the name of the referenced resource We must take into account possible mod-name as first traversal element

func TraversalAsString

func TraversalAsString(traversal hcl.Traversal) string

TraversalAsString converts a traversal to a path string (if an absolute traversal is passed - convert to relative)

func TraversalAsStringSlice

func TraversalAsStringSlice(traversal hcl.Traversal) []string

TraversalAsStringSlice converts a traversal to a path string (if an absolute traversal is passed - convert to relative)

func TraversalsEqual

func TraversalsEqual(t1, t2 hcl.Traversal) bool

Types

type SliceTypeConstraint

type SliceTypeConstraint interface {
	[]bool |
		[]string |
		[]int | []int8 | []int16 | []int32 | []int64 |
		[]uint | []uint8 | []uint16 | []uint32 | []uint64 | []uintptr |
		[]float32 | []float64 |
		[]complex64 | []complex128 |
		[]interface{} | interface{}
}

Jump to

Keyboard shortcuts

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