Documentation
¶
Overview ¶
Package shared provides utilities shared between terraform and its subpackages.
Index ¶
- Constants
- func ApplyRunOptions(info *schema.ConfigAndStacksInfo, opts *RunOptions)
- func BackendExecutionFlags() *flags.FlagRegistry
- func CheckTerraformFlags(info *schema.ConfigAndStacksInfo) error
- func ComponentsArgCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func FilterDeployableComponents(terraformComponents map[string]any) []string
- func HandleInteractiveComponentStackSelection(info *schema.ConfigAndStacksInfo, cmd *cobra.Command) error
- func HandleInteractiveIdentitySelection(info *schema.ConfigAndStacksInfo) error
- func HandlePathResolutionError(err error) error
- func HandlePromptError(err error, name string) error
- func HasMultiComponentFlags(info *schema.ConfigAndStacksInfo) bool
- func HasNonAffectedMultiFlags(info *schema.ConfigAndStacksInfo) bool
- func HasSingleComponentFlags(info *schema.ConfigAndStacksInfo) bool
- func IsComponentDeployable(componentConfig any) bool
- func IsMultiComponentExecution(info *schema.ConfigAndStacksInfo) bool
- func PromptForComponent(cmd *cobra.Command, stack string) (string, error)
- func PromptForStack(cmd *cobra.Command, component string) (string, error)
- func RegisterCompletions(tfCmd *cobra.Command)
- func RegisterIdentityFlags(registry *flags.FlagRegistry)
- func ResolveAndPromptForArgs(info *schema.ConfigAndStacksInfo, cmd *cobra.Command) error
- func ResolveComponentPath(info *schema.ConfigAndStacksInfo, commandName string) error
- func StackFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func TerraformPlanHideContains(values []string, target string) bool
- func ValidateRunOptions(opts *RunOptions) error
- func ValidateStackExists(cmd *cobra.Command, stack string) error
- func WithBackendExecutionFlags() flags.Option
- type RunOptions
Constants ¶
const ( TerraformFailureModeFailFast = "fail-fast" TerraformFailureModeKeepGoing = "keep-going" TerraformLogOrderStream = "stream" TerraformLogOrderGrouped = "grouped" )
Variables ¶
This section is empty.
Functions ¶
func ApplyRunOptions ¶ added in v1.225.0
func ApplyRunOptions(info *schema.ConfigAndStacksInfo, opts *RunOptions)
ApplyRunOptions transfers parsed options to the info struct.
func BackendExecutionFlags ¶ added in v1.225.0
func BackendExecutionFlags() *flags.FlagRegistry
BackendExecutionFlags returns flags for commands that generate backend files or run init.
func CheckTerraformFlags ¶ added in v1.225.0
func CheckTerraformFlags(info *schema.ConfigAndStacksInfo) error
CheckTerraformFlags checks the usage of the single-component and multi-component flags.
func ComponentsArgCompletion ¶
func ComponentsArgCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
ComponentsArgCompletion provides shell completion for component positional arguments. Checks for --stack flag and filters components accordingly.
func FilterDeployableComponents ¶ added in v1.205.0
FilterDeployableComponents returns only components that can be deployed. Filters out abstract and disabled components from the terraform components map. Returns a sorted slice of deployable component names.
func HandleInteractiveComponentStackSelection ¶ added in v1.225.0
func HandleInteractiveComponentStackSelection(info *schema.ConfigAndStacksInfo, cmd *cobra.Command) error
HandleInteractiveComponentStackSelection prompts for missing component and stack.
func HandleInteractiveIdentitySelection ¶ added in v1.225.0
func HandleInteractiveIdentitySelection(info *schema.ConfigAndStacksInfo) error
HandleInteractiveIdentitySelection handles the case where --identity was used without a value.
func HandlePathResolutionError ¶ added in v1.225.0
HandlePathResolutionError wraps path resolution errors with appropriate hints.
func HandlePromptError ¶
HandlePromptError processes errors from interactive prompts. Returns nil if the error should be ignored, or the error if it should propagate.
func HasMultiComponentFlags ¶ added in v1.225.0
func HasMultiComponentFlags(info *schema.ConfigAndStacksInfo) bool
HasMultiComponentFlags checks if any multi-component flags are set.
func HasNonAffectedMultiFlags ¶ added in v1.225.0
func HasNonAffectedMultiFlags(info *schema.ConfigAndStacksInfo) bool
HasNonAffectedMultiFlags checks if multi-component flags, excluding --affected, are set. Tags and labels compose with --affected to narrow the affected set.
func HasSingleComponentFlags ¶ added in v1.225.0
func HasSingleComponentFlags(info *schema.ConfigAndStacksInfo) bool
HasSingleComponentFlags checks if single-component flags are set.
func IsComponentDeployable ¶ added in v1.205.0
IsComponentDeployable checks if a component can be deployed (not abstract, not disabled). Returns false for components with metadata.type: abstract or metadata.enabled: false.
func IsMultiComponentExecution ¶ added in v1.225.0
func IsMultiComponentExecution(info *schema.ConfigAndStacksInfo) bool
IsMultiComponentExecution checks if the command should be routed to multi-component execution.
func PromptForComponent ¶
PromptForComponent shows an interactive selector for component selection. If stack is provided, filters components to only those in that stack.
Unlike the generic flags prompts, this loads the option list with explicit error handling so that a failure to enumerate components (e.g. `describe stacks` errored) surfaces the real cause, and an empty list yields a clear "no components" message — instead of silently falling through to a misleading "component is required" error.
func PromptForStack ¶
PromptForStack shows an interactive selector for stack selection. If component is provided, filters stacks to only those containing the component. The selected stack is written back to the cmd "stack" flag so PostRunE hooks (which re-parse args via ProcessCommandLineArgs) observe the selected value.
Like PromptForComponent, it surfaces load errors and an explicit "no stacks" message instead of silently returning empty.
func RegisterCompletions ¶ added in v1.225.0
RegisterCompletions registers component and identity completion functions for a terraform subcommand.
func RegisterIdentityFlags ¶ added in v1.225.0
func RegisterIdentityFlags(registry *flags.FlagRegistry)
RegisterIdentityFlags adds identity and authentication related flags.
func ResolveAndPromptForArgs ¶ added in v1.225.0
func ResolveAndPromptForArgs(info *schema.ConfigAndStacksInfo, cmd *cobra.Command) error
ResolveAndPromptForArgs handles path resolution and interactive prompts for component/stack.
func ResolveComponentPath ¶ added in v1.225.0
func ResolveComponentPath(info *schema.ConfigAndStacksInfo, commandName string) error
ResolveComponentPath resolves a path-based component argument to a component name.
func StackFlagCompletion ¶
func StackFlagCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
StackFlagCompletion provides shell completion for the --stack flag. If a component was provided as the first positional argument, it filters stacks to only those containing that component.
func TerraformPlanHideContains ¶ added in v1.225.0
TerraformPlanHideContains reports whether values contains target, ignoring case and whitespace.
func ValidateRunOptions ¶ added in v1.225.0
func ValidateRunOptions(opts *RunOptions) error
ValidateRunOptions normalizes and validates Terraform run options.
func ValidateStackExists ¶ added in v1.205.0
ValidateStackExists checks if the provided stack name exists and returns an error with suggestions if it doesn't. The cmd parameter is used to respect global CLI flags (--base-path, --config, --config-path, --profile).
func WithBackendExecutionFlags ¶ added in v1.225.0
WithBackendExecutionFlags returns a flags.Option that adds backend execution flags.
Types ¶
type RunOptions ¶ added in v1.225.0
type RunOptions struct {
// Processing flags.
ProcessTemplates bool
ProcessFunctions bool
UseMocks bool
Skip []string
// Execution flags.
DryRun bool
SkipInit bool
InitPassVars bool
// Backend execution flags.
AutoGenerateBackendFile string
InitRunReconfigure string
// Plan/Apply/Deploy specific flags.
// NOTE: --verify-plan is deliberately NOT parsed here. Viper cannot
// distinguish `--verify-plan=false` from the flag being unset, so the
// tri-state resolution reads the Cobra flag directly via
// resolveVerifyPlanMode (cmd/terraform/utils.go).
PlanFile string
PlanSkipPlanfile bool
DeployRunInit bool
// Multi-component flags.
Query string
Components []string
Tags []string
Labels map[string]string
All bool
Affected bool
// IncludeDependencies/IncludeDependents expand the selection with the
// dependency closure: 0 = off, -1 = unlimited depth, N>0 = N levels.
IncludeDependencies int
IncludeDependents int
// Graph-backed Terraform concurrency.
MaxConcurrency int
FailureMode string
LogOrder string
PlanHide []string
PlanHideNoChanges bool
PlanSummaryFile string
// Status upload flag.
UploadStatus bool
// AppendArgs are extra terraform pass-through flags injected by the caller
// (e.g. `-json` for `terraform test` in CI). They are appended to
// info.AdditionalArgsAndFlags so they reach the terraform command directly,
// bypassing Cobra positional-arg parsing.
AppendArgs []string
}
RunOptions contains shared flags from the terraform parser.
func ParseRunOptions ¶ added in v1.225.0
func ParseRunOptions(v *viper.Viper) (*RunOptions, error)
ParseRunOptions parses and validates shared terraform flags from Viper.