Documentation
¶
Overview ¶
Package output provides functionality to format and export component outputs (e.g. Terraform outputs, CloudFormation stack Outputs) in various formats suitable for CI/CD workflows, scripts, and configuration files.
Index ¶
- Constants
- Variables
- func FlattenMap(m map[string]any, prefix, separator string) map[string]any
- func FormatOutputs(outputs map[string]any, format Format) (string, error)
- func FormatOutputsWithOptions(outputs map[string]any, format Format, opts FormatOptions) (string, error)
- func FormatSingleValue(key string, value any, format Format) (string, error)
- func FormatSingleValueWithOptions(key string, value any, format Format, opts FormatOptions) (string, error)
- func IsComplexValue(value any) bool
- func TransformOutputKeys(outputs map[string]any, opts FormatOptions) (map[string]any, error)
- func ValidateSingleValueFormat(value any, format Format) error
- func WriteToFile(filePath string, content string) error
- type Format
- type FormatOptions
Constants ¶
const DefaultFileMode = 0o644
DefaultFileMode is the file mode for output files.
const DefaultFlattenSeparator = "_"
DefaultFlattenSeparator is the default separator for flattening nested keys.
Variables ¶
var ScalarOnlyFormats = []Format{FormatCSV, FormatTSV, FormatEnv, FormatDotenv, FormatBash}
ScalarOnlyFormats are formats that only support scalar values (not maps/lists).
var SupportedFormats = []string{"json", "yaml", "hcl", "env", "dotenv", "bash", "csv", "tsv", "table", "github"}
SupportedFormats lists all supported output formats.
Functions ¶
func FlattenMap ¶
FlattenMap recursively flattens nested maps and arrays into a single-level map with compound keys. For example: {"config": {"host": "localhost", "port": 3000}} becomes {"config_host": "localhost", "config_port": 3000} with separator "_". Arrays are flattened with numeric indices: {"hosts": ["a", "b"]} becomes {"hosts_0": "a", "hosts_1": "b"}. When two entries flatten to the same key, the first one in sorted key order is kept. Use TransformOutputKeys to report such collisions as an error instead.
func FormatOutputs ¶
FormatOutputs converts an outputs map to the specified format.
func FormatOutputsWithOptions ¶
func FormatOutputsWithOptions(outputs map[string]any, format Format, opts FormatOptions) (string, error)
FormatOutputsWithOptions converts terraform outputs map to the specified format with options.
func FormatSingleValue ¶
FormatSingleValue formats a single terraform output value. For scalar formats (env, dotenv, bash, csv, tsv), complex values (maps/lists) are not supported. For structured formats (json, yaml, hcl), any value type is supported.
func FormatSingleValueWithOptions ¶
func FormatSingleValueWithOptions(key string, value any, format Format, opts FormatOptions) (string, error)
FormatSingleValueWithOptions formats a single terraform output value with options.
func IsComplexValue ¶
IsComplexValue returns true if the value is a map or slice (not a scalar).
func TransformOutputKeys ¶
TransformOutputKeys applies the key transformations selected in opts to outputs and returns the result. It flattens first (when opts.Flatten is set) and then uppercases (when opts.Uppercase is set). Both transformations can map two different outputs to the same name, for example `port` and `PORT` with --uppercase, or `db = { host = ... }` and `db_host` with --flatten. Writing both into one map would silently keep only one of the values, so a collision is reported as ErrOutputKeyCollision naming both outputs, before anything is formatted or written.
func ValidateSingleValueFormat ¶
ValidateSingleValueFormat checks if a format supports a single complex value. CSV/TSV formats do not support single complex values (maps/lists).
func WriteToFile ¶
WriteToFile writes content to a file, creating it if it doesn't exist or appending to it if it does.
Types ¶
type Format ¶
type Format string
Format represents output format types.
const ( // FormatJSON outputs as JSON object: {"key": "value"}. FormatJSON Format = "json" // FormatYAML outputs as YAML: key: value. FormatYAML Format = "yaml" // FormatHCL outputs as HCL: key = "value". FormatHCL Format = "hcl" // FormatEnv outputs as env vars: key=value (GitHub Actions style). FormatEnv Format = "env" // FormatDotenv outputs as dotenv: key='value'. FormatDotenv Format = "dotenv" // FormatBash outputs as bash exports: export key='value'. FormatBash Format = "bash" // FormatCSV outputs as CSV: key,value. FormatCSV Format = "csv" // FormatTSV outputs as TSV: key<tab>value. FormatTSV Format = "tsv" // FormatTable outputs as a styled table with Key/Value columns. FormatTable Format = "table" // FormatGitHub outputs for GitHub Actions $GITHUB_OUTPUT file. // Uses KEY=value for simple values, heredoc syntax for multiline values. FormatGitHub Format = "github" )
type FormatOptions ¶
type FormatOptions struct {
// Uppercase converts keys to uppercase (useful for environment variables).
Uppercase bool
// Flatten recursively expands nested maps and arrays into flat key/value pairs.
// For example, {"config": {"host": "localhost"}} becomes {"config_host": "localhost"}.
// Arrays are flattened with numeric indices: {"hosts": ["a", "b"]} becomes {"hosts_0": "a", "hosts_1": "b"}.
Flatten bool
// FlattenSeparator is the separator used when flattening nested keys (default: "_").
FlattenSeparator string
// AtmosConfig provides configuration for syntax highlighting and color preferences.
AtmosConfig *schema.AtmosConfiguration
}
FormatOptions provides options for output formatting.
func (FormatOptions) GetFlattenSeparator ¶
func (o FormatOptions) GetFlattenSeparator() string
GetFlattenSeparator returns the flatten separator, using the default if not set.