2017-01-19 05:47:18 +01:00
|
|
|
// Package backend provides interfaces that the CLI uses to interact with
|
|
|
|
// Terraform. A backend provides the abstraction that allows the same CLI
|
|
|
|
// to simultaneously support both local and remote operations for seamlessly
|
|
|
|
// using Terraform in a team environment.
|
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2017-02-27 22:51:03 +01:00
|
|
|
"errors"
|
2017-04-01 21:42:13 +02:00
|
|
|
"time"
|
2017-01-19 05:47:18 +01:00
|
|
|
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 19:33:53 +02:00
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2018-02-23 02:43:21 +01:00
|
|
|
"github.com/hashicorp/terraform/command/clistate"
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 19:33:53 +02:00
|
|
|
"github.com/hashicorp/terraform/configs"
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/hashicorp/terraform/configs/configload"
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
"github.com/hashicorp/terraform/configs/configschema"
|
|
|
|
"github.com/hashicorp/terraform/plans"
|
|
|
|
"github.com/hashicorp/terraform/plans/planfile"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
2017-01-19 05:47:18 +01:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
2018-10-31 16:45:03 +01:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
2017-01-19 05:47:18 +01:00
|
|
|
)
|
|
|
|
|
2018-07-04 17:24:49 +02:00
|
|
|
// DefaultStateName is the name of the default, initial state that every
|
|
|
|
// backend must have. This state cannot be deleted.
|
2017-02-21 16:48:00 +01:00
|
|
|
const DefaultStateName = "default"
|
|
|
|
|
2018-10-31 16:45:03 +01:00
|
|
|
var (
|
|
|
|
// ErrDefaultWorkspaceNotSupported is returned when an operation does not
|
|
|
|
// support using the default workspace, but requires a named workspace to
|
|
|
|
// be selected.
|
|
|
|
ErrDefaultWorkspaceNotSupported = errors.New("default workspace not supported\n" +
|
|
|
|
"You can create a new workspace with the \"workspace new\" command.")
|
2018-07-04 17:24:49 +02:00
|
|
|
|
2018-10-31 16:45:03 +01:00
|
|
|
// ErrOperationNotSupported is returned when an unsupported operation
|
|
|
|
// is detected by the configured backend.
|
|
|
|
ErrOperationNotSupported = errors.New("operation not supported")
|
|
|
|
|
|
|
|
// ErrWorkspacesNotSupported is an error returned when a caller attempts
|
|
|
|
// to perform an operation on a workspace other than "default" for a
|
|
|
|
// backend that doesn't support multiple workspaces.
|
|
|
|
//
|
|
|
|
// The caller can detect this to do special fallback behavior or produce
|
|
|
|
// a specific, helpful error message.
|
|
|
|
ErrWorkspacesNotSupported = errors.New("workspaces not supported")
|
|
|
|
)
|
|
|
|
|
|
|
|
// InitFn is used to initialize a new backend.
|
|
|
|
type InitFn func() Backend
|
2017-02-27 22:51:03 +01:00
|
|
|
|
2017-01-19 05:47:18 +01:00
|
|
|
// Backend is the minimal interface that must be implemented to enable Terraform.
|
|
|
|
type Backend interface {
|
2018-03-21 02:43:02 +01:00
|
|
|
// ConfigSchema returns a description of the expected configuration
|
|
|
|
// structure for the receiving backend.
|
|
|
|
//
|
|
|
|
// This method does not have any side-effects for the backend and can
|
|
|
|
// be safely used before configuring.
|
|
|
|
ConfigSchema() *configschema.Block
|
|
|
|
|
|
|
|
// ValidateConfig checks the validity of the values in the given
|
|
|
|
// configuration, assuming that its structure has already been validated
|
|
|
|
// per the schema returned by ConfigSchema.
|
|
|
|
//
|
|
|
|
// This method does not have any side-effects for the backend and can
|
|
|
|
// be safely used before configuring. It also does not consult any
|
|
|
|
// external data such as environment variables, disk files, etc. Validation
|
|
|
|
// that requires such external data should be deferred until the
|
|
|
|
// Configure call.
|
|
|
|
//
|
|
|
|
// If error diagnostics are returned then the configuration is not valid
|
|
|
|
// and must not subsequently be passed to the Configure method.
|
|
|
|
//
|
|
|
|
// This method may return configuration-contextual diagnostics such
|
|
|
|
// as tfdiags.AttributeValue, and so the caller should provide the
|
|
|
|
// necessary context via the diags.InConfigBody method before returning
|
|
|
|
// diagnostics to the user.
|
|
|
|
ValidateConfig(cty.Value) tfdiags.Diagnostics
|
|
|
|
|
|
|
|
// Configure uses the provided configuration to set configuration fields
|
|
|
|
// within the backend.
|
|
|
|
//
|
|
|
|
// The given configuration is assumed to have already been validated
|
|
|
|
// against the schema returned by ConfigSchema and passed validation
|
|
|
|
// via ValidateConfig.
|
|
|
|
//
|
|
|
|
// This method may be called only once per backend instance, and must be
|
|
|
|
// called before all other methods except where otherwise stated.
|
|
|
|
//
|
|
|
|
// If error diagnostics are returned, the internal state of the instance
|
|
|
|
// is undefined and no other methods may be called.
|
|
|
|
Configure(cty.Value) tfdiags.Diagnostics
|
2017-01-19 05:47:18 +01:00
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
// StateMgr returns the state manager for the given workspace name.
|
2017-02-27 20:00:18 +01:00
|
|
|
//
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
// If the returned state manager also implements statemgr.Locker then
|
|
|
|
// it's the caller's responsibility to call Lock and Unlock as appropriate.
|
2017-02-27 20:00:18 +01:00
|
|
|
//
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
// If the named workspace doesn't exist, or if it has no state, it will
|
|
|
|
// be created either immediately on this call or the first time
|
|
|
|
// PersistState is called, depending on the state manager implementation.
|
|
|
|
StateMgr(workspace string) (statemgr.Full, error)
|
2017-02-27 20:00:18 +01:00
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
// DeleteWorkspace removes the workspace with the given name if it exists.
|
|
|
|
//
|
|
|
|
// DeleteWorkspace cannot prevent deleting a state that is in use. It is
|
|
|
|
// the responsibility of the caller to hold a Lock for the state manager
|
|
|
|
// belonging to this workspace before calling this method.
|
|
|
|
DeleteWorkspace(name string) error
|
|
|
|
|
|
|
|
// States returns a list of the names of all of the workspaces that exist
|
|
|
|
// in this backend.
|
|
|
|
Workspaces() ([]string, error)
|
2017-01-19 05:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enhanced implements additional behavior on top of a normal backend.
|
|
|
|
//
|
|
|
|
// Enhanced backends allow customizing the behavior of Terraform operations.
|
|
|
|
// This allows Terraform to potentially run operations remotely, load
|
|
|
|
// configurations from external sources, etc.
|
|
|
|
type Enhanced interface {
|
|
|
|
Backend
|
|
|
|
|
|
|
|
// Operation performs a Terraform operation such as refresh, plan, apply.
|
|
|
|
// It is up to the implementation to determine what "performing" means.
|
|
|
|
// This DOES NOT BLOCK. The context returned as part of RunningOperation
|
|
|
|
// should be used to block for completion.
|
2017-02-02 00:16:16 +01:00
|
|
|
// If the state used in the operation can be locked, it is the
|
|
|
|
// responsibility of the Backend to lock the state for the duration of the
|
|
|
|
// running operation.
|
2017-01-19 05:47:18 +01:00
|
|
|
Operation(context.Context, *Operation) (*RunningOperation, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local implements additional behavior on a Backend that allows local
|
|
|
|
// operations in addition to remote operations.
|
|
|
|
//
|
|
|
|
// This enables more behaviors of Terraform that require more data such
|
|
|
|
// as `console`, `import`, `graph`. These require direct access to
|
|
|
|
// configurations, variables, and more. Not all backends may support this
|
|
|
|
// so we separate it out into its own optional interface.
|
|
|
|
type Local interface {
|
|
|
|
// Context returns a runnable terraform Context. The operation parameter
|
|
|
|
// doesn't need a Type set but it needs other options set such as Module.
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
Context(*Operation) (*terraform.Context, statemgr.Full, tfdiags.Diagnostics)
|
2017-01-19 05:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// An operation represents an operation for Terraform to execute.
|
|
|
|
//
|
|
|
|
// Note that not all fields are supported by all backends and can result
|
|
|
|
// in an error if set. All backend implementations should show user-friendly
|
|
|
|
// errors explaining any incorrectly set values. For example, the local
|
|
|
|
// backend doesn't support a PlanId being set.
|
|
|
|
//
|
|
|
|
// The operation options are purposely designed to have maximal compatibility
|
|
|
|
// between Terraform and Terraform Servers (a commercial product offered by
|
|
|
|
// HashiCorp). Therefore, it isn't expected that other implementation support
|
|
|
|
// every possible option. The struct here is generalized in order to allow
|
|
|
|
// even partial implementations to exist in the open, without walling off
|
|
|
|
// remote functionality 100% behind a commercial wall. Anyone can implement
|
|
|
|
// against this interface and have Terraform interact with it just as it
|
|
|
|
// would with HashiCorp-provided Terraform Servers.
|
|
|
|
type Operation struct {
|
|
|
|
// Type is the operation to perform.
|
|
|
|
Type OperationType
|
|
|
|
|
|
|
|
// PlanId is an opaque value that backends can use to execute a specific
|
|
|
|
// plan for an apply operation.
|
|
|
|
//
|
|
|
|
// PlanOutBackend is the backend to store with the plan. This is the
|
|
|
|
// backend that will be used when applying the plan.
|
|
|
|
PlanId string
|
|
|
|
PlanRefresh bool // PlanRefresh will do a refresh before a plan
|
|
|
|
PlanOutPath string // PlanOutPath is the path to save the plan
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
PlanOutBackend *plans.Backend
|
2017-01-19 05:47:18 +01:00
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
// ConfigDir is the path to the directory containing the configuration's
|
|
|
|
// root module.
|
|
|
|
ConfigDir string
|
|
|
|
|
|
|
|
// ConfigLoader is a configuration loader that can be used to load
|
|
|
|
// configuration from ConfigDir.
|
|
|
|
ConfigLoader *configload.Loader
|
2017-01-19 05:47:18 +01:00
|
|
|
|
|
|
|
// Plan is a plan that was passed as an argument. This is valid for
|
|
|
|
// plan and apply arguments but may not work for all backends.
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
PlanFile *planfile.Reader
|
2017-01-19 05:47:18 +01:00
|
|
|
|
|
|
|
// The options below are more self-explanatory and affect the runtime
|
|
|
|
// behavior of the operation.
|
2018-10-31 16:45:03 +01:00
|
|
|
AutoApprove bool
|
2017-06-13 03:30:57 +02:00
|
|
|
Destroy bool
|
2018-10-31 16:45:03 +01:00
|
|
|
DestroyForce bool
|
|
|
|
Parallelism int
|
terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.
The three main goals here are:
- Use the configuration models from the "configs" package instead of the
older models in the "config" package, which is now deprecated and
preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
new "lang" package, instead of the Interpolator type and related
functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
rather than hand-constructed strings. This is not critical to support
the above, but was a big help during the implementation of these other
points since it made it much more explicit what kind of address is
expected in each context.
Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.
I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-04-30 19:33:53 +02:00
|
|
|
Targets []addrs.Targetable
|
|
|
|
Variables map[string]UnparsedVariableValue
|
2017-01-19 05:47:18 +01:00
|
|
|
|
|
|
|
// Input/output/control options.
|
|
|
|
UIIn terraform.UIInput
|
|
|
|
UIOut terraform.UIOutput
|
2017-02-02 00:16:16 +01:00
|
|
|
|
|
|
|
// If LockState is true, the Operation must Lock any
|
|
|
|
// state.Lockers for its duration, and Unlock when complete.
|
|
|
|
LockState bool
|
2017-02-27 22:43:31 +01:00
|
|
|
|
2018-02-23 02:43:21 +01:00
|
|
|
// StateLocker is used to lock the state while providing UI feedback to the
|
|
|
|
// user. This will be supplied by the Backend itself.
|
|
|
|
StateLocker clistate.Locker
|
|
|
|
|
2017-04-01 21:42:13 +02:00
|
|
|
// The duration to retry obtaining a State lock.
|
|
|
|
StateLockTimeout time.Duration
|
|
|
|
|
2017-05-31 18:37:31 +02:00
|
|
|
// Workspace is the name of the workspace that this operation should run
|
|
|
|
// in, which controls which named state is used.
|
|
|
|
Workspace string
|
2017-01-19 05:47:18 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
// HasConfig returns true if and only if the operation has a ConfigDir value
|
|
|
|
// that refers to a directory containing at least one Terraform configuration
|
|
|
|
// file.
|
|
|
|
func (o *Operation) HasConfig() bool {
|
|
|
|
return o.ConfigLoader.IsConfigDir(o.ConfigDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config loads the configuration that the operation applies to, using the
|
|
|
|
// ConfigDir and ConfigLoader fields within the receiving operation.
|
|
|
|
func (o *Operation) Config() (*configs.Config, tfdiags.Diagnostics) {
|
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
config, hclDiags := o.ConfigLoader.LoadConfig(o.ConfigDir)
|
|
|
|
diags = diags.Append(hclDiags)
|
|
|
|
return config, diags
|
|
|
|
}
|
|
|
|
|
2017-01-19 05:47:18 +01:00
|
|
|
// RunningOperation is the result of starting an operation.
|
|
|
|
type RunningOperation struct {
|
|
|
|
// For implementers of a backend, this context should not wrap the
|
2018-09-19 21:01:40 +02:00
|
|
|
// passed in context. Otherwise, cancelling the parent context will
|
2017-01-19 05:47:18 +01:00
|
|
|
// immediately mark this context as "done" but those aren't the semantics
|
|
|
|
// we want: we want this context to be done only when the operation itself
|
|
|
|
// is fully done.
|
|
|
|
context.Context
|
|
|
|
|
2018-02-10 00:10:52 +01:00
|
|
|
// Stop requests the operation to complete early, by calling Stop on all
|
|
|
|
// the plugins. If the process needs to terminate immediately, call Cancel.
|
|
|
|
Stop context.CancelFunc
|
|
|
|
|
|
|
|
// Cancel is the context.CancelFunc associated with the embedded context,
|
|
|
|
// and can be called to terminate the operation early.
|
|
|
|
// Once Cancel is called, the operation should return as soon as possible
|
|
|
|
// to avoid running operations during process exit.
|
|
|
|
Cancel context.CancelFunc
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
// Result is the exit status of the operation, populated only after the
|
|
|
|
// operation has completed.
|
|
|
|
Result OperationResult
|
2017-01-19 05:47:18 +01:00
|
|
|
|
|
|
|
// PlanEmpty is populated after a Plan operation completes without error
|
|
|
|
// to note whether a plan is empty or has changes.
|
|
|
|
PlanEmpty bool
|
|
|
|
|
|
|
|
// State is the final state after the operation completed. Persisting
|
|
|
|
// this state is managed by the backend. This should only be read
|
|
|
|
// after the operation completes to avoid read/write races.
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
State *states.State
|
2017-01-19 05:47:18 +01:00
|
|
|
}
|
2018-03-21 02:43:02 +01:00
|
|
|
|
|
|
|
// OperationResult describes the result status of an operation.
|
|
|
|
type OperationResult int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// OperationSuccess indicates that the operation completed as expected.
|
|
|
|
OperationSuccess OperationResult = 0
|
|
|
|
|
|
|
|
// OperationFailure indicates that the operation encountered some sort
|
|
|
|
// of error, and thus may have been only partially performed or not
|
|
|
|
// performed at all.
|
|
|
|
OperationFailure OperationResult = 1
|
|
|
|
)
|
2018-03-28 00:31:05 +02:00
|
|
|
|
|
|
|
func (r OperationResult) ExitStatus() int {
|
|
|
|
return int(r)
|
|
|
|
}
|