mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-16 16:01:49 -04:00
84 lines
3.3 KiB
Go
84 lines
3.3 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package backend
|
|
|
|
import (
|
|
"github.com/opentofu/opentofu/internal/command/arguments"
|
|
"github.com/opentofu/opentofu/internal/command/views"
|
|
"github.com/opentofu/opentofu/internal/tofu"
|
|
)
|
|
|
|
// CLI is an optional interface that can be implemented to be initialized
|
|
// with information from the OpenTofu CLI. If this is implemented, this
|
|
// initialization function will be called with data to help interact better
|
|
// with a CLI.
|
|
//
|
|
// This interface was created to improve backend interaction with the
|
|
// official OpenTofu CLI while making it optional for API users to have
|
|
// to provide full CLI interaction to every backend.
|
|
//
|
|
// If you're implementing a Backend, it is acceptable to require CLI
|
|
// initialization. In this case, your backend should be coded to error
|
|
// on other methods (such as State, Operation) if CLI initialization was not
|
|
// done with all required fields.
|
|
type CLI interface {
|
|
Backend
|
|
|
|
// CLIInit is called once with options. The options passed to this
|
|
// function may not be modified after calling this since they can be
|
|
// read/written at any time by the Backend implementation.
|
|
//
|
|
// This may be called before or after Configure is called, so if settings
|
|
// here affect configurable settings, care should be taken to handle
|
|
// whether they should be overwritten or not.
|
|
CLIInit(*CLIOpts) error
|
|
}
|
|
|
|
// CLIOpts are the options passed into CLIInit for the CLI interface.
|
|
//
|
|
// These options represent the functionality the CLI exposes and often
|
|
// maps to meta-flags available on every CLI (such as -input).
|
|
//
|
|
// When implementing a backend, it isn't expected that every option applies.
|
|
// Your backend should be documented clearly to explain to end users what
|
|
// options have an affect and what won't. In some cases, it may even make sense
|
|
// to error in your backend when an option is set so that users don't make
|
|
// a critically incorrect assumption about behavior.
|
|
type CLIOpts struct {
|
|
// View is used by the remote and cloud backends to print the progress
|
|
// of their actions.
|
|
View views.BackendRemote
|
|
|
|
// StateArgs carries the state related configurations. Refer to the
|
|
// arguments.State for more details.
|
|
// In this particular case, an empty arguments.State#BackupPath will result
|
|
// in skipping the backup entirely and the new state will just overwrite the old
|
|
// one.
|
|
StateArgs arguments.State
|
|
|
|
// ContextOpts are the base context options to set when initializing a
|
|
// OpenTofu context. Many of these will be overridden or merged by
|
|
// Operation. See Operation for more details.
|
|
ContextOpts *tofu.ContextOpts
|
|
|
|
// Input will ask for necessary input prior to performing any operations.
|
|
//
|
|
// Validation will perform validation prior to running an operation. The
|
|
// variable naming doesn't match the style of others since we have a func
|
|
// Validate.
|
|
Input bool
|
|
Validation bool
|
|
|
|
// RunningInAutomation indicates that commands are being run by an
|
|
// automated system rather than directly at a command prompt.
|
|
//
|
|
// This is a hint not to produce messages that expect that a user can
|
|
// run a follow-up command, perhaps because OpenTofu is running in
|
|
// some sort of workflow automation tool that abstracts away the
|
|
// exact commands that are being run.
|
|
RunningInAutomation bool
|
|
}
|