genhcl

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package genhcl implements generate_hcl code generation.

Index

Constants

View Source
const (
	// HeaderMagic is the current header magic string used by generate_hcl code generation.
	HeaderMagic = "TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT"

	// HeaderV0 is the deprecated header string used by generate_hcl code generation.
	HeaderV0 = "// GENERATED BY TERRAMATE: DO NOT EDIT"
)
View Source
const (
	// ErrParsing indicates the failure of parsing the generate_hcl block.
	ErrParsing errors.Kind = "parsing generate_hcl block"

	// ErrContentEval indicates the failure to evaluate the content block.
	ErrContentEval errors.Kind = "evaluating content"

	// ErrConditionEval indicates the failure to evaluate the condition attribute.
	ErrConditionEval errors.Kind = "evaluating condition attribute"

	// ErrInheritEval indicates the failure to evaluate the inherit attribute.
	ErrInheritEval errors.Kind = "evaluating inherit attribute"

	// ErrInvalidConditionType indicates the condition attribute
	// has an invalid type.
	ErrInvalidConditionType errors.Kind = "invalid condition type"

	// ErrInvalidInheritType indicates the inherit attribute has an invalid type.
	ErrInvalidInheritType errors.Kind = "invalid inherit type"

	// ErrInvalidDynamicIterator indicates that the iterator of a tm_dynamic block
	// is invalid.
	ErrInvalidDynamicIterator errors.Kind = "invalid tm_dynamic.iterator"

	// ErrInvalidDynamicLabels indicates that the labels of a tm_dynamic block is invalid.
	ErrInvalidDynamicLabels errors.Kind = "invalid tm_dynamic.labels"

	// ErrDynamicAttrsEval indicates that the attributes of a tm_dynamic cant be evaluated.
	ErrDynamicAttrsEval errors.Kind = "evaluating tm_dynamic.attributes"

	// ErrDynamicConditionEval indicates that the condition of a tm_dynamic cant be evaluated.
	ErrDynamicConditionEval errors.Kind = "evaluating tm_dynamic.condition"

	// ErrDynamicAttrsConflict indicates fields of tm_dynamic conflicts.
	ErrDynamicAttrsConflict errors.Kind = "tm_dynamic.attributes and tm_dynamic.content have conflicting fields"
)

Variables

This section is empty.

Functions

func DefaultHeader added in v0.5.0

func DefaultHeader() string

DefaultHeader returns the header for the default comment style.

func Header(comment CommentStyle) string

Header returns the HCL header based on the comment style.

Types

type CommentStyle added in v0.5.0

type CommentStyle int

CommentStyle is the configured comment style that must be generated.

const (
	SlashComment CommentStyle = iota
	HashComment

	DefaultComment = SlashComment
)

Comment styles supported.

func CommentStyleFromConfig added in v0.5.0

func CommentStyleFromConfig(tree *config.Tree) CommentStyle

CommentStyleFromConfig returns the CommentStyle from the configuration or the default if not defined.

func (CommentStyle) String added in v0.5.0

func (c CommentStyle) String() string

type HCL

type HCL struct {
	// contains filtered or unexported fields
}

HCL represents generated HCL code from a single block. Is contains parsed and evaluated code on it and information about the origin of the generated code.

func Load

func Load(
	root *config.Root,
	st *config.Stack,
	globals *eval.Object,
	vendorDir project.Path,
	vendorRequests chan<- event.VendorRequest,
) ([]HCL, error)

Load loads from the file system all generate_hcl for a given stack. It will navigate the file system from the stack dir until it reaches rootdir, loading generate_hcl and merging them appropriately.

All generate_file blocks must have unique labels, even ones at different directories. Any conflicts will be reported as an error.

Metadata and globals for the stack are used on the evaluation of the generate_hcl blocks.

The rootdir MUST be an absolute path.

func (HCL) Asserts

func (h HCL) Asserts() []config.Assert

Asserts returns all (if any) of the evaluated assert configs of the generate_hcl block. If HCL.Condition returns false then assert configs will always be empty since they are not evaluated at all in that case.

func (HCL) Body

func (h HCL) Body() string

Body returns a string representation of the HCL code or an empty string if the config itself is empty.

func (HCL) Condition

func (h HCL) Condition() bool

Condition returns the evaluated condition attribute for the generated code.

func (HCL) Context

func (h HCL) Context() string

Context of the generate_hcl block.

func (HCL) Header

func (h HCL) Header() string

Header returns the header of the generated HCL file.

func (HCL) Label

func (h HCL) Label() string

Label of the original generate_hcl block.

func (HCL) Range

func (h HCL) Range() info.Range

Range returns the range information of the generate_file block.

func (HCL) String

func (h HCL) String() string

Jump to

Keyboard shortcuts

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