hclhelpers

package
v1.6.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: AGPL-3.0 Imports: 21 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 ExprIsNativeQuotedString added in v1.6.0

func ExprIsNativeQuotedString(expr hcl.Expression) bool

ExprIsNativeQuotedString determines whether the given expression looks like it's a quoted string in the HCL native syntax.

This should be used sparingly only for situations where our legacy HCL decoding would've expected a keyword or reference in quotes but our new decoding expects the keyword or reference to be provided directly as an identifier-based expression.

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 connection block schema this is passed to the plugin who will validate and parse it

func HclSchemaForStruct added in v1.6.0

func HclSchemaForStruct(target any) (*hcl.BodySchema, error)

func HclSyntaxBlockRangePointer

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

func IsCollectionOrTuple added in v1.6.0

func IsCollectionOrTuple(typ cty.Type) bool

Checks if the given type is a collection or a tuple

func IsComplexType added in v1.6.0

func IsComplexType(typ cty.Type) bool

func IsEnumValueCompatibleWithType added in v1.6.0

func IsEnumValueCompatibleWithType(ctyType cty.Type, enumValues cty.Value) bool

func IsListLike added in v1.6.0

func IsListLike(typ cty.Type) bool

func IsMapLike added in v1.6.0

func IsMapLike(typ cty.Type) bool

func IsNestedCapsuleType added in v1.6.0

func IsNestedCapsuleType(t cty.Type) (reflect.Type, bool)

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

func ValidateSettingWithEnum added in v1.6.0

func ValidateSettingWithEnum(setting cty.Value, enum cty.Value) (bool, error)

Types

type HclTag added in v1.6.0

type HclTag struct {
	Tag   string
	Block bool
	// was optional specified in the hcl tag
	// (NOTE - the field may be optional even if not specified, so this is a pointer)
	Optional *bool
}

func NewHclTag added in v1.6.0

func NewHclTag(tag string) (HclTag, error)

NewHclTag creates a new HclTag from a string and validates it.

type Pos added in v1.6.0

type Pos struct {
	Line   int `json:"line" cty:"line"`
	Column int `json:"column" cty:"column"`
	Byte   int `json:"byte" cty:"byte"`
}

Pos represents a single position in a source file This is a direct re-implementation of hcl.Pos, allowing us to control JSON serialization

func NewPos added in v1.6.0

func NewPos(sourcePos hcl.Pos) Pos

func (Pos) HclPos added in v1.6.0

func (r Pos) HclPos() hcl.Pos

type Range added in v1.6.0

type Range struct {
	// Filename is the name of the file into which this range's positions point.
	Filename string `json:"filename,omitempty" cty:"filename"`

	// Start and End represent the bounds of this range. Start is inclusive and End is exclusive.
	Start Pos `json:"start,omitempty" cty:"start"`
	End   Pos `json:"end,omitempty" cty:"end"`
}

Range represents a span of characters between two positions in a source file. This is a direct re-implementation of hcl.Range, allowing us to control JSON serialization

func NewRange added in v1.6.0

func NewRange(sourceRange hcl.Range) Range

func (Range) Equals added in v1.6.0

func (r Range) Equals(declRange Range) bool

func (Range) HclRange added in v1.6.0

func (r Range) HclRange() hcl.Range

func (Range) HclRangePointer added in v1.6.0

func (r Range) HclRangePointer() *hcl.Range

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