generate

package
v1.206.2 Latest Latest
Warning

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

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

Documentation

Overview

Package generate provides functionality to generate files from the generate section in Atmos stack configuration.

Package generate provides functionality to generate files for Terraform components from the generate section in Atmos stack configuration.

Index

Constants

View Source
const (
	ExtJSON   = ".json"
	ExtYAML   = ".yaml"
	ExtYML    = ".yml"
	ExtTF     = ".tf"
	ExtHCL    = ".hcl"
	ExtTFVars = ".tfvars"
)

File extension constants for serialization format detection.

Variables

This section is empty.

Functions

func BuildTemplateContext

func BuildTemplateContext(info *schema.ConfigAndStacksInfo) map[string]any

BuildTemplateContext builds the template context from ConfigAndStacksInfo.

func BuildTemplateContextFromSection

func BuildTemplateContextFromSection(componentSection map[string]any, componentName, stackName string) map[string]any

BuildTemplateContextFromSection builds template context from a component section map. Used when processing all components without full ProcessStacks.

func ExtractTerraformSection

func ExtractTerraformSection(stackSection any) map[string]any

ExtractTerraformSection extracts the terraform section from a stack.

func GetComponentPath

func GetComponentPath(componentSection map[string]any, componentName string) string

GetComponentPath gets the component path from component section.

func GetFilenamesForComponent

func GetFilenamesForComponent(componentSection map[string]any) []string

GetFilenamesForComponent returns the list of filenames from the generate section. This is used by terraform clean to know which files to delete.

func GetGenerateFilenames

func GetGenerateFilenames(generateSection map[string]any) []string

GetGenerateFilenames extracts the list of filenames from a generate section. This is used by terraform clean to know which files to delete.

func GetGenerateSectionFromComponent

func GetGenerateSectionFromComponent(componentSection map[string]any) map[string]any

GetGenerateSectionFromComponent extracts the generate section from a component.

func IsAbstractComponent

func IsAbstractComponent(componentSection map[string]any) bool

IsAbstractComponent checks if a component is abstract.

func MatchesStackFilter

func MatchesStackFilter(stackName string, filters []string) bool

MatchesStackFilter checks if a stack matches the filter patterns. It checks both the full stack file path and the basename, allowing users to filter by either "deploy/dev" (full path) or "dev" (basename). Uses filepath.Match which supports glob patterns.

Types

type ExecAdapter

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

ExecAdapter adapts internal/exec functions to the StackProcessor interface.

func NewExecAdapter

func NewExecAdapter(processStacks ExecStackProcessor, findStacksMap ExecFindStacksMap) *ExecAdapter

NewExecAdapter creates a new adapter that wraps internal/exec functions.

func (*ExecAdapter) FindStacksMap

func (a *ExecAdapter) FindStacksMap(atmosConfig *schema.AtmosConfiguration, ignoreMissingFiles bool) (map[string]any, map[string]map[string]any, error)

FindStacksMap implements StackProcessor.FindStacksMap by delegating to internal/exec.FindStacksMap.

func (*ExecAdapter) ProcessStacks

func (a *ExecAdapter) ProcessStacks(
	atmosConfig *schema.AtmosConfiguration,
	info schema.ConfigAndStacksInfo,
	checkStack bool,
	processTemplates bool,
	processYamlFunctions bool,
	skip []string,
	authManager auth.AuthManager,
) (schema.ConfigAndStacksInfo, error)

ProcessStacks implements StackProcessor.ProcessStacks by delegating to internal/exec.ProcessStacks.

type ExecFindStacksMap

type ExecFindStacksMap func(atmosConfig *schema.AtmosConfiguration, ignoreMissingFiles bool) (map[string]any, map[string]map[string]any, error)

ExecFindStacksMap is a function type that matches the FindStacksMap signature in internal/exec.

type ExecStackProcessor

type ExecStackProcessor func(
	atmosConfig *schema.AtmosConfiguration,
	info schema.ConfigAndStacksInfo,
	checkStack bool,
	processTemplates bool,
	processYamlFunctions bool,
	skip []string,
	authManager auth.AuthManager,
) (schema.ConfigAndStacksInfo, error)

ExecStackProcessor is a function type that matches the ProcessStacks signature in internal/exec.

type GenerateConfig

type GenerateConfig struct {
	// DryRun when true, shows what would be generated without writing.
	DryRun bool
	// Clean when true, deletes generated files instead of creating.
	Clean bool
}

GenerateConfig contains configuration for file generation.

type GenerateResult

type GenerateResult struct {
	// Filename is the name of the generated file.
	Filename string
	// Path is the full path where the file was written.
	Path string
	// Created indicates if the file was created (vs updated).
	Created bool
	// Deleted indicates if the file was deleted (clean mode).
	Deleted bool
	// Skipped indicates if the file was skipped (dry-run mode).
	Skipped bool
	// Error contains any error that occurred.
	Error error
}

GenerateResult contains information about a generated file.

func GenerateFiles

func GenerateFiles(
	generateSection map[string]any,
	componentDir string,
	templateContext map[string]any,
	config GenerateConfig,
) ([]GenerateResult, error)

GenerateFiles generates files from the generate section of a component configuration. It returns a slice of GenerateResult describing what was generated.

type Service

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

Service provides file generation operations for Terraform components.

func NewService

func NewService(processor StackProcessor) *Service

NewService creates a new generate service with the given stack processor.

func (*Service) ExecuteForAll

func (s *Service) ExecuteForAll(
	atmosConfig *schema.AtmosConfiguration,
	stacks []string,
	components []string,
	dryRun bool,
	clean bool,
) error

ExecuteForAll generates files for all terraform components.

func (*Service) ExecuteForComponent

func (s *Service) ExecuteForComponent(
	atmosConfig *schema.AtmosConfiguration,
	component string,
	stack string,
	dryRun bool,
	clean bool,
) error

ExecuteForComponent generates files for a single terraform component.

func (*Service) GenerateFilesForComponent

func (s *Service) GenerateFilesForComponent(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, workingDir string) error

GenerateFilesForComponent generates files from the generate section during terraform execution. This is called automatically when auto_generate_files is enabled.

type StackProcessor

type StackProcessor interface {
	// ProcessStacks processes stacks and returns component configuration.
	ProcessStacks(
		atmosConfig *schema.AtmosConfiguration,
		info schema.ConfigAndStacksInfo,
		checkStack bool,
		processTemplates bool,
		processYamlFunctions bool,
		skip []string,
		authManager auth.AuthManager,
	) (schema.ConfigAndStacksInfo, error)

	// FindStacksMap discovers all stacks in the configuration.
	FindStacksMap(atmosConfig *schema.AtmosConfiguration, ignoreMissingFiles bool) (map[string]any, map[string]map[string]any, error)
}

StackProcessor defines the interface for processing stacks. This allows for dependency injection and easier testing.

Jump to

Keyboard shortcuts

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