parser

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package parser provides HCL parsing functionality for Terraform files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendConfig

type BackendConfig struct {
	Type   string            // "s3", "gcs", "azurerm"
	Config map[string]string // evaluated string attributes: bucket, key, region, etc.
}

BackendConfig represents a module's terraform backend configuration.

type Dependency

type Dependency struct {
	From            *discovery.Module
	To              *discovery.Module
	Type            string
	RemoteStateName string
}

Dependency represents a dependency between two modules.

type DependencyExtractor

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

DependencyExtractor extracts module dependencies from parsed Terraform files.

func NewDependencyExtractor

func NewDependencyExtractor(parser ModuleParser, index *discovery.ModuleIndex) *DependencyExtractor

NewDependencyExtractor creates a new dependency extractor.

func (*DependencyExtractor) ExtractAllDependencies

func (de *DependencyExtractor) ExtractAllDependencies(ctx context.Context) (map[string]*ModuleDependencies, []error)

ExtractAllDependencies extracts dependencies for all modules in the index.

func (*DependencyExtractor) ExtractDependencies

func (de *DependencyExtractor) ExtractDependencies(ctx context.Context, module *discovery.Module) (*ModuleDependencies, error)

ExtractDependencies extracts dependencies for a single module.

type LibraryDependency

type LibraryDependency struct {
	ModuleCall  *ModuleCall
	LibraryPath string
}

LibraryDependency represents a dependency on a library module.

type ModuleCall

type ModuleCall struct {
	Name         string
	Source       string
	Version      string
	IsLocal      bool
	ResolvedPath string
}

ModuleCall represents a module block in Terraform.

type ModuleDependencies

type ModuleDependencies struct {
	Module              *discovery.Module
	Dependencies        []*Dependency
	LibraryDependencies []*LibraryDependency
	DependsOn           []string
	Errors              []error
}

ModuleDependencies contains all dependencies for a module.

type ModuleParser

type ModuleParser interface {
	ParseModule(ctx context.Context, modulePath string) (*ParsedModule, error)
	ResolveWorkspacePath(ref *RemoteStateRef, modulePath string, locals, variables map[string]cty.Value) ([]string, error)
}

ModuleParser is the interface for parsing Terraform modules.

type ParsedModule

type ParsedModule struct {
	Path         string
	Locals       map[string]cty.Value
	Variables    map[string]cty.Value
	Backend      *BackendConfig
	RemoteStates []*RemoteStateRef
	ModuleCalls  []*ModuleCall
	Files        map[string]*hcl.File
	Diagnostics  hcl.Diagnostics
}

ParsedModule contains the parsed content of a Terraform module.

type Parser

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

Parser handles parsing of Terraform HCL files.

func NewParser

func NewParser(segments []string) *Parser

NewParser creates a new HCL parser with the given pattern segments.

func (*Parser) ParseModule

func (p *Parser) ParseModule(ctx context.Context, modulePath string) (*ParsedModule, error)

ParseModule parses all Terraform files in a module directory.

func (*Parser) ResolveWorkspacePath

func (p *Parser) ResolveWorkspacePath(ref *RemoteStateRef, modulePath string, locals, variables map[string]cty.Value) ([]string, error)

ResolveWorkspacePath resolves workspace paths from a remote state config using the module's locals, variables, and path-derived segment values.

func (*Parser) Segments

func (p *Parser) Segments() []string

Segments returns the parser's configured pattern segments.

type RemoteStateRef

type RemoteStateRef struct {
	Name         string
	Backend      string
	Config       map[string]hcl.Expression
	ForEach      hcl.Expression
	WorkspaceDir string
	RawBody      hcl.Body
}

RemoteStateRef represents a terraform_remote_state data source reference.

Jump to

Keyboard shortcuts

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