terraform

package
v0.0.0-...-762db6c Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlanHasNoChanges = iota
	PlanHasChanges
	PlanHasDestructiveChanges
)

Variables

View Source
var (
	ErrRunnerStopped         = errors.New("Terraform runner was stopped.")
	ErrTerraformApplyAborted = errors.New("Terraform apply aborted.")
)

Functions

func DestroyPipeline

func DestroyPipeline(r RunnerInterface, name string) error

Types

type BaseInfraRunnerOptions

type BaseInfraRunnerOptions struct {
	AutoDismissDestructive           bool
	AutoApprove                      bool
	CommanderMode                    bool
	StateCache                       dstate.Cache
	ClusterState                     []byte
	AdditionalStateSaverDestinations []SaverDestination
}

TODO: use same runner in check+converge only in commander mode, use as-is otherwise, implement destroy and bootstrap

type BaseInfrastructureDestructiveChanges

type BaseInfrastructureDestructiveChanges struct {
	PlanDestructiveChanges
	OutputBrokenReason string      `json:"output_broken_reason,omitempty"`
	OutputZonesChanged ValueChange `json:"output_zones_changed,omitempty"`
}

type BootstrapNodeRunnerOptions

type BootstrapNodeRunnerOptions struct {
	AutoApprove                      bool
	NodeName                         string
	NodeGroupName                    string
	NodeGroupStep                    string
	NodeIndex                        int
	NodeCloudConfig                  string
	AdditionalStateSaverDestinations []SaverDestination
}

type CMDExecutor

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

CMDExecutor straightforward cmd executor which provides convenient output and handles quit signal.

func (*CMDExecutor) Exec

func (c *CMDExecutor) Exec(args ...string) (int, error)

func (*CMDExecutor) Output

func (c *CMDExecutor) Output(args ...string) ([]byte, error)

func (*CMDExecutor) Stop

func (c *CMDExecutor) Stop()

type ChangeActionSettings

type ChangeActionSettings struct {
	AutoDismissDestructive bool
	AutoApprove            bool
	SkipChangesOnDeny      bool
}

type DestroyBaseInfraRunnerOptions

type DestroyBaseInfraRunnerOptions struct {
	AutoApprove bool
}

type DestroyNodeRunnerOptions

type DestroyNodeRunnerOptions struct {
	AutoApprove   bool
	NodeName      string
	NodeGroupName string
	NodeGroupStep string
	NodeIndex     int
}

type DummyHook

type DummyHook struct{}

func (*DummyHook) AfterAction

func (c *DummyHook) AfterAction() error

func (*DummyHook) BeforeAction

func (c *DummyHook) BeforeAction() (runPostAction bool, err error)

func (*DummyHook) IsReady

func (c *DummyHook) IsReady() error

type Executor

type Executor interface {
	Output(...string) ([]byte, error)
	Exec(...string) (int, error)
	Stop()
}

type InfraActionHook

type InfraActionHook interface {
	BeforeAction() (runAfterAction bool, err error)
	IsReady() error
	AfterAction() error
}

type NodeDeleteRunnerOptions

type NodeDeleteRunnerOptions struct {
	AutoDismissDestructive bool
	AutoApprove            bool

	NodeName        string
	NodeGroupName   string
	NodeGroupStep   string
	NodeIndex       int
	NodeState       []byte
	NodeCloudConfig string

	CommanderMode                    bool
	StateCache                       dstate.Cache
	AdditionalStateSaverDestinations []SaverDestination
}

type NodeRunnerOptions

type NodeRunnerOptions struct {
	AutoDismissDestructive bool
	AutoApprove            bool

	NodeName        string
	NodeGroupName   string
	NodeGroupStep   string
	NodeIndex       int
	NodeState       []byte
	NodeCloudConfig string

	CommanderMode                    bool
	StateCache                       dstate.Cache
	AdditionalStateSaverDestinations []SaverDestination
	ReadinessChecker                 InfraActionHook
}

type PipelineOutputs

type PipelineOutputs struct {
	TerraformState []byte
	CloudDiscovery []byte

	BastionHost string

	MasterIPForSSH     string
	NodeInternalIP     string
	KubeDataDevicePath string
}

func ApplyPipeline

func ApplyPipeline(r RunnerInterface, name string, extractFn func(r RunnerInterface) (*PipelineOutputs, error)) (*PipelineOutputs, error)

func GetBaseInfraResult

func GetBaseInfraResult(r RunnerInterface) (*PipelineOutputs, error)

func GetMasterNodeResult

func GetMasterNodeResult(r RunnerInterface) (*PipelineOutputs, error)

func OnlyState

func OnlyState(r RunnerInterface) (*PipelineOutputs, error)

type PlanDestructiveChanges

type PlanDestructiveChanges struct {
	ResourcesDeleted   []ValueChange `json:"resources_deleted,omitempty"`
	ResourcesRecreated []ValueChange `json:"resourced_recreated,omitempty"`
}

type PlanOptions

type PlanOptions struct {
	Destroy bool
}

type Runner

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

func NewImmutableRunnerFromConfig

func NewImmutableRunnerFromConfig(cfg *config.MetaConfig, step string) *Runner

func NewRunner

func NewRunner(provider, prefix, layout, step string, stateCache state.Cache) *Runner

func NewRunnerFromConfig

func NewRunnerFromConfig(cfg *config.MetaConfig, step string, stateCache state.Cache) *Runner

func (*Runner) Apply

func (r *Runner) Apply() error

func (*Runner) Destroy

func (r *Runner) Destroy() error

func (*Runner) GetChangesInPlan

func (r *Runner) GetChangesInPlan() int

func (*Runner) GetPlanDestructiveChanges

func (r *Runner) GetPlanDestructiveChanges() *PlanDestructiveChanges

func (*Runner) GetPlanPath

func (r *Runner) GetPlanPath() string

func (*Runner) GetState

func (r *Runner) GetState() ([]byte, error)

func (*Runner) GetStep

func (r *Runner) GetStep() string

func (*Runner) GetTerraformExecutor

func (r *Runner) GetTerraformExecutor() Executor

func (*Runner) GetTerraformOutput

func (r *Runner) GetTerraformOutput(output string) ([]byte, error)

func (*Runner) Init

func (r *Runner) Init() error

func (*Runner) Plan

func (r *Runner) Plan(opts PlanOptions) error

func (*Runner) ResourcesQuantityInState

func (r *Runner) ResourcesQuantityInState() int

func (*Runner) Stop

func (r *Runner) Stop()

Stop interrupts the current runner command and sets a flag to prevent executions of next runner commands.

func (*Runner) WithAdditionalStateSaverDestination

func (r *Runner) WithAdditionalStateSaverDestination(destinations ...SaverDestination) *Runner

WithAdditionalStateSaverDestination by default we use intermediate save state to cache destination

func (*Runner) WithAllowedCachedState

func (r *Runner) WithAllowedCachedState(flag bool) *Runner

func (*Runner) WithAutoApprove

func (r *Runner) WithAutoApprove(flag bool) *Runner

func (*Runner) WithAutoDismissDestructiveChanges

func (r *Runner) WithAutoDismissDestructiveChanges(flag bool) *Runner

func (*Runner) WithCache

func (r *Runner) WithCache(cache state.Cache) *Runner

func (*Runner) WithConfirm

func (r *Runner) WithConfirm(confirm func() *input.Confirmation) *Runner

func (*Runner) WithHook

func (r *Runner) WithHook(h InfraActionHook) *Runner

func (*Runner) WithName

func (r *Runner) WithName(name string) *Runner

func (*Runner) WithSingleShotMode

func (r *Runner) WithSingleShotMode(enabled bool) RunnerInterface

func (*Runner) WithSkipChangesOnDeny

func (r *Runner) WithSkipChangesOnDeny(flag bool) *Runner

func (*Runner) WithState

func (r *Runner) WithState(stateData []byte) *Runner

func (*Runner) WithStatePath

func (r *Runner) WithStatePath(statePath string) *Runner

func (*Runner) WithVariables

func (r *Runner) WithVariables(variablesData []byte) *Runner

type RunnerInterface

type RunnerInterface interface {
	Init() error
	Apply() error
	Plan(opts PlanOptions) error
	Destroy() error
	Stop()

	ResourcesQuantityInState() int
	GetTerraformOutput(output string) ([]byte, error)
	GetState() ([]byte, error)
	GetStep() string
	GetChangesInPlan() int
	GetPlanDestructiveChanges() *PlanDestructiveChanges
	GetPlanPath() string
	GetTerraformExecutor() Executor
}

type SaverDestination

type SaverDestination interface {
	SaveState(outputs *PipelineOutputs) error
}

type SingleShotRunner

type SingleShotRunner struct {
	*Runner
	// contains filtered or unexported fields
}

func NewSingleShotRunner

func NewSingleShotRunner(runner *Runner) *SingleShotRunner

func (*SingleShotRunner) Apply

func (r *SingleShotRunner) Apply() (err error)

func (*SingleShotRunner) Destroy

func (r *SingleShotRunner) Destroy() (err error)

func (*SingleShotRunner) GetTerraformOutput

func (r *SingleShotRunner) GetTerraformOutput(output string) ([]byte, error)

func (*SingleShotRunner) Init

func (r *SingleShotRunner) Init() (err error)

func (*SingleShotRunner) Plan

func (r *SingleShotRunner) Plan(opts PlanOptions) (err error)

func (*SingleShotRunner) ResourcesQuantityInState

func (r *SingleShotRunner) ResourcesQuantityInState() int

func (*SingleShotRunner) Stop

func (r *SingleShotRunner) Stop()

type StateSaver

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

func NewStateSaver

func NewStateSaver(destinations []SaverDestination) *StateSaver

func (*StateSaver) DoneCh

func (s *StateSaver) DoneCh() chan struct{}

func (*StateSaver) FsEventHandler

func (s *StateSaver) FsEventHandler(event fsnotify.Event)

func (*StateSaver) IsStarted

func (s *StateSaver) IsStarted() bool

func (*StateSaver) Start

func (s *StateSaver) Start(runner *Runner) error

Start creates a new file watcher for r.statePath and a chan to stop it.

func (*StateSaver) Stop

func (s *StateSaver) Stop()

Stop is blocked until doneCh is closed.

type TerraformContext

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

func NewTerraformContext

func NewTerraformContext() *TerraformContext

func (*TerraformContext) GetBootstrapBaseInfraRunner

func (f *TerraformContext) GetBootstrapBaseInfraRunner(metaConfig *config.MetaConfig, stateCache dstate.Cache) RunnerInterface

func (*TerraformContext) GetBootstrapNodeRunner

func (f *TerraformContext) GetBootstrapNodeRunner(metaConfig *config.MetaConfig, stateCache dstate.Cache, opts BootstrapNodeRunnerOptions) RunnerInterface

func (*TerraformContext) GetCheckBaseInfraRunner

func (f *TerraformContext) GetCheckBaseInfraRunner(metaConfig *config.MetaConfig, opts BaseInfraRunnerOptions) RunnerInterface

TODO(dhctl-for-commander): Use same tf-runner for check & converge in commander mode only, keep things as-is without changes

func (*TerraformContext) GetCheckNodeDeleteRunner

func (f *TerraformContext) GetCheckNodeDeleteRunner(metaConfig *config.MetaConfig, opts NodeDeleteRunnerOptions) RunnerInterface

func (*TerraformContext) GetCheckNodeRunner

func (f *TerraformContext) GetCheckNodeRunner(metaConfig *config.MetaConfig, opts NodeRunnerOptions) RunnerInterface

func (*TerraformContext) GetConvergeBaseInfraRunner

func (f *TerraformContext) GetConvergeBaseInfraRunner(metaConfig *config.MetaConfig, opts BaseInfraRunnerOptions) RunnerInterface

func (*TerraformContext) GetConvergeNodeDeleteRunner

func (f *TerraformContext) GetConvergeNodeDeleteRunner(metaConfig *config.MetaConfig, opts NodeDeleteRunnerOptions) RunnerInterface

func (*TerraformContext) GetConvergeNodeRunner

func (f *TerraformContext) GetConvergeNodeRunner(metaConfig *config.MetaConfig, opts NodeRunnerOptions) RunnerInterface

func (*TerraformContext) GetDestroyBaseInfraRunner

func (f *TerraformContext) GetDestroyBaseInfraRunner(metaConfig *config.MetaConfig, stateCache dstate.Cache, opts DestroyBaseInfraRunnerOptions) RunnerInterface

func (*TerraformContext) GetDestroyNodeRunner

func (f *TerraformContext) GetDestroyNodeRunner(metaConfig *config.MetaConfig, stateCache dstate.Cache, opts DestroyNodeRunnerOptions) RunnerInterface

type TerraformPlan

type TerraformPlan map[string]any

type ValueChange

type ValueChange struct {
	CurrentValue interface{} `json:"current_value,omitempty"`
	NextValue    interface{} `json:"next_value,omitempty"`
}

Jump to

Keyboard shortcuts

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