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
- func BuildTemplateContext(info *schema.ConfigAndStacksInfo) map[string]any
- func BuildTemplateContextFromSection(componentSection map[string]any, componentName, stackName string) map[string]any
- func ExtractTerraformSection(stackSection any) map[string]any
- func GetComponentPath(componentSection map[string]any, componentName string) string
- func GetFilenamesForComponent(componentSection map[string]any) []string
- func GetGenerateFilenames(generateSection map[string]any) []string
- func GetGenerateSectionFromComponent(componentSection map[string]any) map[string]any
- func IsAbstractComponent(componentSection map[string]any) bool
- func MatchesStackFilter(stackName string, filters []string) bool
- type ExecAdapter
- func (a *ExecAdapter) FindStacksMap(atmosConfig *schema.AtmosConfiguration, ignoreMissingFiles bool) (map[string]any, map[string]map[string]any, error)
- func (a *ExecAdapter) ProcessStacks(atmosConfig *schema.AtmosConfiguration, info schema.ConfigAndStacksInfo, ...) (schema.ConfigAndStacksInfo, error)
- type ExecFindStacksMap
- type ExecStackProcessor
- type GenerateConfig
- type GenerateResult
- type Service
- func (s *Service) ExecuteForAll(atmosConfig *schema.AtmosConfiguration, stacks []string, components []string, ...) error
- func (s *Service) ExecuteForComponent(atmosConfig *schema.AtmosConfiguration, component string, stack string, ...) error
- func (s *Service) GenerateFilesForComponent(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, ...) error
- type StackProcessor
Constants ¶
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 ¶
ExtractTerraformSection extracts the terraform section from a stack.
func GetComponentPath ¶
GetComponentPath gets the component path from component section.
func GetFilenamesForComponent ¶
GetFilenamesForComponent returns the list of filenames from the generate section. This is used by terraform clean to know which files to delete.
func GetGenerateFilenames ¶
GetGenerateFilenames extracts the list of filenames from a generate section. This is used by terraform clean to know which files to delete.
func GetGenerateSectionFromComponent ¶
GetGenerateSectionFromComponent extracts the generate section from a component.
func IsAbstractComponent ¶
IsAbstractComponent checks if a component is abstract.
func MatchesStackFilter ¶
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.