Documentation ¶
Index ¶
- type ApplyResult
- type CallbackFn
- type ExecMode
- type FileProducer
- type FileProducerOption
- type ImportResult
- type InUse
- type MainConfiguration
- type NoOpProviderRunner
- type NoOpProviderScheduler
- type Operation
- func (o *Operation) EndTime() time.Time
- func (o *Operation) Error() error
- func (o *Operation) Flush()
- func (o *Operation) IsEnded() bool
- func (o *Operation) IsRunning() bool
- func (o *Operation) MarkEnd()
- func (o *Operation) MarkStart(t string) bool
- func (o *Operation) SetError(err error)
- func (o *Operation) StartTime() time.Time
- type PlanResult
- type ProviderConfiguration
- type ProviderHandle
- type ProviderRequirement
- type ProviderRunner
- type ProviderScheduler
- type RefreshResult
- type Setup
- type SetupFn
- type SharedProvider
- type SharedProviderOption
- func WithNativeProviderArgs(args ...string) SharedProviderOption
- func WithNativeProviderExecutor(e exec.Interface) SharedProviderOption
- func WithNativeProviderLogger(logger logging.Logger) SharedProviderOption
- func WithNativeProviderName(n string) SharedProviderOption
- func WithNativeProviderPath(p string) SharedProviderOption
- func WithProtocolVersion(protocolVersion int) SharedProviderOption
- type SharedProviderScheduler
- type SharedProviderSchedulerOption
- type StoreCleaner
- type Terraform
- type Workspace
- func (w *Workspace) Apply(ctx context.Context) (ApplyResult, error)
- func (w *Workspace) ApplyAsync(callback CallbackFn) error
- func (w *Workspace) Destroy(ctx context.Context) error
- func (w *Workspace) DestroyAsync(callback CallbackFn) error
- func (w *Workspace) Import(ctx context.Context, tr resource.Terraformed) (ImportResult, error)
- func (w *Workspace) Plan(ctx context.Context) (PlanResult, error)
- func (w *Workspace) Refresh(ctx context.Context) (RefreshResult, error)
- func (w *Workspace) UseProvider(inuse InUse, attachmentConfig string)
- type WorkspaceFinalizer
- type WorkspaceOption
- func WithAferoFs(fs afero.Fs) WorkspaceOption
- func WithExecutor(e k8sExec.Interface) WorkspaceOption
- func WithFilterFn(filterFn func(string) string) WorkspaceOption
- func WithLastOperation(lo *Operation) WorkspaceOption
- func WithLogger(l logging.Logger) WorkspaceOption
- func WithProviderInUse(providerInUse InUse) WorkspaceOption
- type WorkspaceProviderScheduler
- type WorkspaceStore
- type WorkspaceStoreOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyResult ¶
ApplyResult contains the state after the apply operation.
type CallbackFn ¶
CallbackFn is the type of accepted function that can be called after an async operation is completed.
type FileProducer ¶
type FileProducer struct { Resource resource.Terraformed Setup Setup Dir string Config *config.Resource // contains filtered or unexported fields }
FileProducer exist to serve as cache for the data that is costly to produce every time like parameters and observation maps.
func NewFileProducer ¶
func NewFileProducer(ctx context.Context, client resource.SecretClient, dir string, tr resource.Terraformed, ts Setup, cfg *config.Resource, opts ...FileProducerOption) (*FileProducer, error)
NewFileProducer returns a new FileProducer.
func (*FileProducer) BuildMainTF ¶ added in v1.1.0
func (fp *FileProducer) BuildMainTF() map[string]any
BuildMainTF produces the contents of the mainTF file as a map. This format is conducive to inspection for tests. WriteMainTF calls this function an serializes the result to a file as JSON.
func (*FileProducer) EnsureTFState ¶
func (fp *FileProducer) EnsureTFState(_ context.Context, tfID string) error
EnsureTFState writes the Terraform state that should exist in the filesystem to start any Terraform operation.
func (*FileProducer) WriteMainTF ¶
func (fp *FileProducer) WriteMainTF() (ProviderHandle, error)
WriteMainTF writes the content main configuration file that has the desired state configuration for Terraform.
type FileProducerOption ¶
type FileProducerOption func(*FileProducer)
FileProducerOption allows you to configure FileProducer
func WithFileProducerFeatures ¶
func WithFileProducerFeatures(f *feature.Flags) FileProducerOption
WithFileProducerFeatures configures the active features for the FileProducer.
func WithFileSystem ¶
func WithFileSystem(fs afero.Fs) FileProducerOption
WithFileSystem configures the filesystem to use. Used mostly for testing.
type ImportResult ¶
type ImportResult RefreshResult
ImportResult contains information about the current state of the resource. Same as RefreshResult.
type InUse ¶
type InUse interface { // Increment marks one more user of a shared resource // such as a native plugin process. Increment() // Decrement marks when a user of a shared resource, // such as a native plugin process, has released the resource. Decrement() }
InUse keeps track of the usage of a shared resource, like a native plugin process.
type MainConfiguration ¶
type MainConfiguration struct {
Terraform Terraform `json:"terraform,omitempty"`
}
type NoOpProviderRunner ¶
type NoOpProviderRunner struct{}
NoOpProviderRunner is a no-op ProviderRunner
func NewNoOpProviderRunner ¶
func NewNoOpProviderRunner() NoOpProviderRunner
NewNoOpProviderRunner constructs a new NoOpProviderRunner
func (NoOpProviderRunner) Start ¶
func (NoOpProviderRunner) Start() (string, error)
Start takes no action
type NoOpProviderScheduler ¶
type NoOpProviderScheduler struct{}
NoOpProviderScheduler satisfied the ProviderScheduler interface and is a noop implementation, i.e., it does not schedule any native plugin processes.
func NewNoOpProviderScheduler ¶
func NewNoOpProviderScheduler() NoOpProviderScheduler
NewNoOpProviderScheduler initializes a new NoOpProviderScheduler.
func (NoOpProviderScheduler) Start ¶
func (NoOpProviderScheduler) Start(ProviderHandle) (InUse, string, error)
func (NoOpProviderScheduler) Stop ¶
func (NoOpProviderScheduler) Stop(ProviderHandle) error
type Operation ¶
type Operation struct { Type string // contains filtered or unexported fields }
Operation is the representation of a single Terraform CLI operation.
func (*Operation) IsEnded ¶
IsEnded returns whether the operation has ended, regardless of its result.
func (*Operation) MarkStart ¶
MarkStart marks the operation as started atomically after checking no previous operation is already running. Returns `false` if a previous operation is still in progress.
type PlanResult ¶
PlanResult returns a summary of comparison between desired and current state of the resource.
type ProviderConfiguration ¶
ProviderConfiguration holds the setup configuration body
func (ProviderConfiguration) ToProviderHandle ¶
func (pc ProviderConfiguration) ToProviderHandle() (ProviderHandle, error)
ToProviderHandle converts a provider configuration to a handle for the provider scheduler.
type ProviderHandle ¶
type ProviderHandle string
ProviderHandle represents native plugin (Terraform provider) process handles used by the various schedulers to map Terraform workspaces to these processes.
const ( // InvalidProviderHandle is an invalid ProviderHandle. InvalidProviderHandle ProviderHandle = "" )
type ProviderRequirement ¶
type ProviderRequirement struct { // Source of the provider. An example value is "hashicorp/aws". Source string // Version of the provider. An example value is "4.0" Version string }
ProviderRequirement holds values for the Terraform HCL setup requirements
type ProviderRunner ¶
ProviderRunner is the interface for running Terraform native provider processes in the shared gRPC server mode
type ProviderScheduler ¶
type ProviderScheduler interface { // Start forks or reuses a native plugin process associated with // the supplied ProviderHandle. Start(ProviderHandle) (InUse, string, error) // Stop terminates the native plugin process, if it exists, for // the specified ProviderHandle. Stop(ProviderHandle) error }
ProviderScheduler represents a shared native plugin process scheduler.
type RefreshResult ¶
RefreshResult contains information about the current state of the resource.
type Setup ¶
type Setup struct { // Version is the version of Terraform that this workspace would require as // minimum. Version string // Requirement contains the provider requirements of the workspace to work, // which is mostly the version and source of the provider. Requirement ProviderRequirement // Configuration contains the provider configuration parameters of the given // Terraform provider, such as access token. Configuration ProviderConfiguration // ClientMetadata contains arbitrary metadata that the provider would like // to pass but not available as part of Terraform's provider configuration. // For example, AWS account id is needed for certain ID calculations but is // not part of the Terraform AWS Provider configuration, so it could be // made available only by this map. ClientMetadata map[string]string // Scheduler specifies the provider scheduler to be used for the Terraform // workspace being setup. If not set, no scheduler is configured and // the lifecycle of Terraform provider processes will be managed by // the Terraform CLI. Scheduler ProviderScheduler Meta any FrameworkProvider fwprovider.Provider }
Setup holds values for the Terraform version and setup requirements and configuration body
type SetupFn ¶
SetupFn is a function that returns Terraform setup which contains provider requirement, configuration and Terraform version.
type SharedProvider ¶
type SharedProvider struct {
// contains filtered or unexported fields
}
SharedProvider runs the configured native provider plugin using the supplied command-line args
func NewSharedProvider ¶
func NewSharedProvider(opts ...SharedProviderOption) *SharedProvider
NewSharedProvider instantiates a SharedProvider runner with an OS executor using the supplied options.
func (*SharedProvider) Start ¶
func (sr *SharedProvider) Start() (string, error)
Start starts a shared gRPC server if not already running A logger, native provider's path and command-line arguments to be passed to it must have been properly configured. Returns any errors encountered and the reattachment configuration for the native provider.
func (*SharedProvider) Stop ¶
func (sr *SharedProvider) Stop() error
Stop attempts to stop a shared gRPC server if it's already running.
type SharedProviderOption ¶
type SharedProviderOption func(runner *SharedProvider)
SharedProviderOption lets you configure the shared gRPC runner.
func WithNativeProviderArgs ¶
func WithNativeProviderArgs(args ...string) SharedProviderOption
WithNativeProviderArgs are the arguments to be passed to the native provider
func WithNativeProviderExecutor ¶
func WithNativeProviderExecutor(e exec.Interface) SharedProviderOption
WithNativeProviderExecutor sets the process executor to be used
func WithNativeProviderLogger ¶
func WithNativeProviderLogger(logger logging.Logger) SharedProviderOption
WithNativeProviderLogger configures the logger for the runner.
func WithNativeProviderName ¶
func WithNativeProviderName(n string) SharedProviderOption
WithNativeProviderName configures the Terraform provider name for the runner.
func WithNativeProviderPath ¶
func WithNativeProviderPath(p string) SharedProviderOption
WithNativeProviderPath configures the Terraform provider executable path for the runner.
func WithProtocolVersion ¶
func WithProtocolVersion(protocolVersion int) SharedProviderOption
WithProtocolVersion sets the gRPC protocol version in use between the Terraform CLI and the native provider.
type SharedProviderScheduler ¶
type SharedProviderScheduler struct {
// contains filtered or unexported fields
}
SharedProviderScheduler is a ProviderScheduler that shares a native plugin (Terraform provider) process between MR reconciliation loops whose MRs yield the same ProviderHandle, i.e., whose Terraform resource blocks are configuration-wise identical. SharedProviderScheduler is configured with a max TTL and it will gracefully attempt to replace ProviderRunners whose TTL exceed this maximum, if they are not in-use.
func NewSharedProviderScheduler ¶
func NewSharedProviderScheduler(l logging.Logger, ttl int, opts ...SharedProviderSchedulerOption) *SharedProviderScheduler
NewSharedProviderScheduler initializes a new SharedProviderScheduler with the specified logger and options.
func (*SharedProviderScheduler) Start ¶
func (s *SharedProviderScheduler) Start(h ProviderHandle) (InUse, string, error)
func (*SharedProviderScheduler) Stop ¶
func (s *SharedProviderScheduler) Stop(ProviderHandle) error
type SharedProviderSchedulerOption ¶
type SharedProviderSchedulerOption func(scheduler *SharedProviderScheduler)
SharedProviderSchedulerOption represents an option to configure the SharedProviderScheduler.
func WithSharedProviderOptions ¶
func WithSharedProviderOptions(opts ...SharedProviderOption) SharedProviderSchedulerOption
WithSharedProviderOptions configures the SharedProviderOptions to be passed down to the managed SharedProviders.
type StoreCleaner ¶
type StoreCleaner interface {
Remove(obj xpresource.Object) error
}
StoreCleaner is the interface that the workspace finalizer needs to work with.
type Workspace ¶
type Workspace struct { // LastOperation contains information about the last operation performed. LastOperation *Operation // ProviderHandle is the handle of the associated native Terraform provider // computed from the generated provider resource configuration block // of the Terraform workspace. ProviderHandle ProviderHandle // contains filtered or unexported fields }
Workspace runs Terraform operations in its directory and holds the information about their statuses.
func NewWorkspace ¶
func NewWorkspace(dir string, opts ...WorkspaceOption) *Workspace
NewWorkspace returns a new Workspace object that operates in the given directory.
func (*Workspace) Apply ¶
func (w *Workspace) Apply(ctx context.Context) (ApplyResult, error)
Apply makes a blocking terraform apply call.
func (*Workspace) ApplyAsync ¶
func (w *Workspace) ApplyAsync(callback CallbackFn) error
ApplyAsync makes a terraform apply call without blocking and calls the given function once that apply call finishes.
func (*Workspace) DestroyAsync ¶
func (w *Workspace) DestroyAsync(callback CallbackFn) error
DestroyAsync makes a non-blocking terraform destroy call. It doesn't accept a callback because destroy operations are not time sensitive as ApplyAsync where you might need to store the server-side computed information as soon as possible.
func (*Workspace) Import ¶
func (w *Workspace) Import(ctx context.Context, tr resource.Terraformed) (ImportResult, error)
Import makes a blocking terraform import call where only the state file is changed with the current state of the resource.
func (*Workspace) Plan ¶
func (w *Workspace) Plan(ctx context.Context) (PlanResult, error)
Plan makes a blocking terraform plan call.
func (*Workspace) Refresh ¶
func (w *Workspace) Refresh(ctx context.Context) (RefreshResult, error)
Refresh makes a blocking terraform apply -refresh-only call where only the state file is changed with the current state of the resource.
func (*Workspace) UseProvider ¶
UseProvider shares a native provider with the receiver Workspace.
type WorkspaceFinalizer ¶
type WorkspaceFinalizer struct { xpresource.Finalizer Store StoreCleaner }
WorkspaceFinalizer removes the workspace from the workspace store and only then calls RemoveFinalizer of the underlying Finalizer.
func NewWorkspaceFinalizer ¶
func NewWorkspaceFinalizer(ws StoreCleaner, af xpresource.Finalizer) *WorkspaceFinalizer
NewWorkspaceFinalizer returns a new WorkspaceFinalizer.
func (*WorkspaceFinalizer) AddFinalizer ¶
func (wf *WorkspaceFinalizer) AddFinalizer(ctx context.Context, obj xpresource.Object) error
AddFinalizer to the supplied Managed resource.
func (*WorkspaceFinalizer) RemoveFinalizer ¶
func (wf *WorkspaceFinalizer) RemoveFinalizer(ctx context.Context, obj xpresource.Object) error
RemoveFinalizer removes the workspace from workspace store before removing the finalizer.
type WorkspaceOption ¶
type WorkspaceOption func(*Workspace)
WorkspaceOption allows you to configure Workspace objects.
func WithAferoFs ¶
func WithAferoFs(fs afero.Fs) WorkspaceOption
WithAferoFs lets you set the fs of WorkspaceStore.
func WithExecutor ¶
func WithExecutor(e k8sExec.Interface) WorkspaceOption
WithExecutor sets the executor of Workspace.
func WithFilterFn ¶
func WithFilterFn(filterFn func(string) string) WorkspaceOption
WithFilterFn configures the debug log sensitive information filtering func.
func WithLastOperation ¶
func WithLastOperation(lo *Operation) WorkspaceOption
WithLastOperation sets the Last Operation of Workspace.
func WithLogger ¶
func WithLogger(l logging.Logger) WorkspaceOption
WithLogger sets the logger of Workspace.
func WithProviderInUse ¶
func WithProviderInUse(providerInUse InUse) WorkspaceOption
WithProviderInUse configures an InUse for keeping track of the shared provider InUse by this Terraform workspace.
type WorkspaceProviderScheduler ¶
type WorkspaceProviderScheduler struct {
// contains filtered or unexported fields
}
WorkspaceProviderScheduler is a ProviderScheduler that shares a native plugin (Terraform provider) process between the Terraform CLI invocations in the context of a single reconciliation loop (belonging to a single workspace). When the managed.ExternalDisconnecter disconnects, the scheduler terminates the native plugin process.
func NewWorkspaceProviderScheduler ¶
func NewWorkspaceProviderScheduler(l logging.Logger, opts ...SharedProviderOption) *WorkspaceProviderScheduler
NewWorkspaceProviderScheduler initializes a new WorkspaceProviderScheduler.
func (*WorkspaceProviderScheduler) Start ¶
func (s *WorkspaceProviderScheduler) Start(h ProviderHandle) (InUse, string, error)
func (*WorkspaceProviderScheduler) Stop ¶
func (s *WorkspaceProviderScheduler) Stop(h ProviderHandle) error
type WorkspaceStore ¶
type WorkspaceStore struct {
// contains filtered or unexported fields
}
WorkspaceStore allows you to manage multiple Terraform workspaces.
func NewWorkspaceStore ¶
func NewWorkspaceStore(l logging.Logger, opts ...WorkspaceStoreOption) *WorkspaceStore
NewWorkspaceStore returns a new WorkspaceStore.
func (*WorkspaceStore) Remove ¶
func (ws *WorkspaceStore) Remove(obj xpresource.Object) error
Remove deletes the workspace directory from the filesystem and erases its record from the store.
func (*WorkspaceStore) Workspace ¶
func (ws *WorkspaceStore) Workspace(ctx context.Context, c resource.SecretClient, tr resource.Terraformed, ts Setup, cfg *config.Resource) (*Workspace, error)
Workspace makes sure the Terraform workspace for the given resource is ready to be used and returns the Workspace object configured to work in that workspace folder in the filesystem.
type WorkspaceStoreOption ¶
type WorkspaceStoreOption func(*WorkspaceStore)
WorkspaceStoreOption lets you configure the workspace store.
func WithDisableInit ¶
func WithDisableInit(disable bool) WorkspaceStoreOption
WithDisableInit disables `terraform init` invocations in case workspace initialization is not needed (e.g., when using the shared gRPC server runtime).
func WithFeatures ¶
func WithFeatures(f *feature.Flags) WorkspaceStoreOption
WithFeatures sets the features of the workspace store.
func WithFs ¶
func WithFs(fs afero.Fs) WorkspaceStoreOption
WithFs lets you set the fs of WorkspaceStore. Used mostly for testing.
func WithProcessReportInterval ¶
func WithProcessReportInterval(d time.Duration) WorkspaceStoreOption
WithProcessReportInterval enables the upjet.terraform.running_processes metric, which periodically reports the total number of Terraform CLI and Terraform provider processes in the system.