hclext

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package hclext provides extended HCL types for tfbreak plugins.

Types align with tflint-plugin-sdk/hclext for ecosystem familiarity. This package provides schema and content types used by the Runner interface to specify what configuration content to retrieve.

Key types:

  • BodySchema: Defines expected attributes and blocks to extract
  • BodyContent: Contains extracted attributes and blocks
  • Attribute: An extracted HCL attribute with expression and range
  • Block: An extracted HCL block with labels and nested content

Conversion functions are provided to translate between these types and the github.com/hashicorp/hcl/v2 equivalents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToHCLBodySchema

func ToHCLBodySchema(schema *BodySchema) *hcl.BodySchema

ToHCLBodySchema converts a BodySchema to an hcl.BodySchema. This is useful when using hcl.Body.Content() or PartialContent().

Types

type Attribute

type Attribute struct {
	// Name is the attribute name.
	Name string
	// Expr is the attribute's value expression.
	// This may be nil when received over gRPC; use Value instead.
	Expr hcl.Expression
	// Value is the pre-evaluated attribute value.
	// This is populated when the attribute is received over gRPC
	// (since hcl.Expression cannot be serialized).
	Value cty.Value
	// Range is the source range of the entire attribute.
	Range hcl.Range
	// NameRange is the source range of just the attribute name.
	NameRange hcl.Range
}

Attribute represents an extracted HCL attribute.

func FromHCLAttribute

func FromHCLAttribute(attr *hcl.Attribute) *Attribute

FromHCLAttribute converts an hcl.Attribute to an Attribute.

type AttributeSchema

type AttributeSchema struct {
	// Name is the attribute name to match.
	Name string
	// Required indicates if the attribute must be present.
	Required bool
}

AttributeSchema represents an expected HCL attribute.

type Block

type Block struct {
	// Type is the block type (e.g., "resource").
	Type string
	// Labels are the block's label values.
	Labels []string
	// Body is the block's body content.
	Body *BodyContent
	// DefRange is the source range of the block definition.
	DefRange hcl.Range
	// TypeRange is the source range of the block type.
	TypeRange hcl.Range
	// LabelRanges are the source ranges of each label.
	LabelRanges []hcl.Range
}

Block represents an extracted HCL block.

func FromHCLBlock

func FromHCLBlock(block *hcl.Block) *Block

FromHCLBlock converts an hcl.Block to a Block. Note: Body content must be extracted separately using the block's Body field.

type BlockSchema

type BlockSchema struct {
	// Type is the block type to match (e.g., "resource", "variable").
	Type string
	// LabelNames are the names for block labels (e.g., ["type", "name"] for resources).
	LabelNames []string
	// Body is the schema for the block's body content.
	Body *BodySchema
}

BlockSchema represents an expected HCL block.

type BodyContent

type BodyContent struct {
	// Attributes maps attribute names to their content.
	Attributes map[string]*Attribute
	// Blocks contains extracted block content.
	Blocks []*Block
}

BodyContent represents extracted content from an HCL body.

func FromHCLBodyContent

func FromHCLBodyContent(content *hcl.BodyContent) *BodyContent

FromHCLBodyContent converts an hcl.BodyContent to a BodyContent. Note: Nested block bodies must be processed separately.

type BodySchema

type BodySchema struct {
	// Attributes defines expected attributes.
	Attributes []AttributeSchema
	// Blocks defines expected nested blocks.
	Blocks []BlockSchema
	// Mode specifies schema matching behavior.
	Mode SchemaMode
}

BodySchema represents the expected structure of an HCL body. Use this to specify what attributes and blocks to extract from configuration.

Example:

schema := &hclext.BodySchema{
    Attributes: []hclext.AttributeSchema{
        {Name: "location", Required: true},
        {Name: "name", Required: true},
    },
    Blocks: []hclext.BlockSchema{
        {Type: "timeouts", LabelNames: nil},
    },
}

type SchemaMode

type SchemaMode int

SchemaMode specifies how schema matching behaves.

const (
	// SchemaDefaultMode requires explicitly declared attributes and blocks.
	SchemaDefaultMode SchemaMode = iota
	// SchemaJustAttributesMode extracts all attributes without explicit declaration.
	SchemaJustAttributesMode
)

Jump to

Keyboard shortcuts

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