hcltools

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTokensForOutput

func CreateTokensForOutput(in string) hclwrite.Tokens

CreateTokensForOutput create slice of tokens, from splitted by dot substrings of in.

func InterfaceToCty

func InterfaceToCty(in interface{}) (cty.Value, error)

InterfaceToCty convert go type to cty.Value(for hlc lib), using hack with JSON marshal/unmarshal.

func IsInlineStruct added in v0.8.0

func IsInlineStruct(field *reflect.StructField) bool

IsInlineStruct looks at the json tag of the given StructField, to determine if it has been marked as "inline" e.g. someField string `json:",inline"`

func IsZero added in v0.8.0

func IsZero(v reflect.Value) bool

IsZero reports whether is considered the zero / empty / unset value fo the type

func Kubernetes2HCL added in v0.8.0

func Kubernetes2HCL(manifest interface{}, dst *hclwrite.Body) error

func Kubernetes2HCLCustom added in v0.8.0

func Kubernetes2HCLCustom(manifest interface{}, key string, rootBody *hclwrite.Body) error

func NormalizeTerraformName added in v0.8.0

func NormalizeTerraformName(s string, toSingular bool, path string) string

normalizeTerraformName converts the given string to snake case and optionally to singular form of the given word s is the string to normalize set toSingular to true to singularize the given word path is the full schema path to the named element Src: https://github.com/sl1pm4t/k2tf

func ProvidersToHCL

func ProvidersToHCL(in interface{}) (*hclwrite.File, error)

func ReplaceStingMarkerInBody

func ReplaceStingMarkerInBody(body *hclwrite.Body, marker, value string)

ReplaceStingMarkerInBody replace all substrings in TokenQuotedLit tokens to value as terraform expression.

func ToTerraformAttributeName added in v0.8.0

func ToTerraformAttributeName(field *reflect.StructField, path string) string

func ToTerraformResourceType added in v0.8.0

func ToTerraformResourceType(obj runtime.Object, blockKind *schema.GroupVersionKind) string

ToTerraformResourceType converts a Kubernetes API Object Type name to the equivalent `terraform-provider-kubernetes` schema name. Src: https://github.com/sl1pm4t/k2tf

func ToTerraformSubBlockName added in v0.8.0

func ToTerraformSubBlockName(field *reflect.StructField, path string) string

func WriteObject added in v0.8.0

func WriteObject(obj runtime.Object, dst *hclwrite.Body) (int, error)

WriteObject converts a Kubernetes runtime.Object to HCL

Types

type ObjectWalker added in v0.8.0

type ObjectWalker struct {
	// The Kubernetes API Object to be walked
	RuntimeObject runtime.Object
	// contains filtered or unexported fields
}

ObjectWalker implements reflectwalk.Walker interfaces It's used to "walk" the Kubernetes API Objects structure and generate an HCL document based on the values defined.

func NewObjectWalker added in v0.8.0

func NewObjectWalker(obj runtime.Object, dst *hclwrite.Body) (*ObjectWalker, error)

NewObjectWalker returns a new ObjectWalker object dst is the hclwrite.Body where HCL blocks will be appended.

func (*ObjectWalker) Enter added in v0.8.0

func (w *ObjectWalker) Enter(l reflectwalk.Location) error

Enter is called by reflectwalk.Walk each time we enter a level

func (*ObjectWalker) Exit added in v0.8.0

Exit is called by reflectwalk each time it exits from a reflectwalk.Location

func (*ObjectWalker) Map added in v0.8.0

func (w *ObjectWalker) Map(m reflect.Value) error

Map is called everytime reflectwalk enters a Map Golang maps are usually output as HCL maps, but sometimes as sub-blocks.

func (*ObjectWalker) MapElem added in v0.8.0

func (w *ObjectWalker) MapElem(m, k, v reflect.Value) error

MapElem is called every time reflectwalk enters a Map element

normalize the element key, and write element value to the HCL block as an attribute value

func (*ObjectWalker) Primitive added in v0.8.0

func (w *ObjectWalker) Primitive(v reflect.Value) error

Primitive is called whenever reflectwalk visits a Primitive value. If it's not a zero value, add an Attribute to the current HCL Block.

func (*ObjectWalker) ResourceName added in v0.8.0

func (w *ObjectWalker) ResourceName() string

ResourceName returns the Terraform Resource name for the Kubernetes Object

func (*ObjectWalker) ResourceType added in v0.8.0

func (w *ObjectWalker) ResourceType() string

ResourceType returns the Terraform Resource type for the Kubernetes Object

func (*ObjectWalker) Slice added in v0.8.0

func (w *ObjectWalker) Slice(v reflect.Value) error

Slice implements reflectwalk.SliceWalker interface, and is called each time reflectwalk enters a Slice Golang slices need to be converted to HCL in one of two ways:

*1 - a simple list of primitive values:

list_name = ["foo", "bar", "baz"]

*2 - a list of complex objects that will be rendered as repeating HCL blocks

container {
	name  = "blah"
	image = "nginx"
}

container {
	name  = "foo"
	image = "sidecar"
}

For the second case, each time we process a SliceElem we need to use the StructField data of the Slice itself, and not the slice elem.

func (*ObjectWalker) SliceElem added in v0.8.0

func (w *ObjectWalker) SliceElem(i int, v reflect.Value) error

SliceElem implements reflectwalk.SliceWalker interface

func (*ObjectWalker) Struct added in v0.8.0

func (w *ObjectWalker) Struct(v reflect.Value) error

Struct is called every time reflectwalk enters a Struct

func (*ObjectWalker) StructField added in v0.8.0

func (w *ObjectWalker) StructField(field reflect.StructField, v reflect.Value) error

StructField is called by reflectwalk whenever it enters a field of a struct. We ignore Invalid fields, or some API fields we don't need to convert to HCL. The rest are added to the StuctField stack so we have access to the StructField data in other funcs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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