Documentation ¶
Overview ¶
Package genhcl implements generate_hcl code generation.
Index ¶
Constants ¶
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" )
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 ¶
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, evalctx *eval.Context, 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 ¶
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 ¶
Body returns a string representation of the HCL code or an empty string if the config itself is empty.