2017-01-19 05:49:01 +01:00
|
|
|
// Package remotestate implements a Backend for remote state implementations
|
|
|
|
// from the state/remote package that also implement a backend schema for
|
|
|
|
// configuration.
|
|
|
|
package remotestate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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/zclconf/go-cty/cty"
|
|
|
|
|
2017-02-21 16:48:00 +01:00
|
|
|
"github.com/hashicorp/terraform/backend"
|
2017-01-19 05:49:01 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/state/remote"
|
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/states/statemgr"
|
2018-03-21 02:43:02 +01:00
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
2017-01-19 05:49:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Backend implements backend.Backend for remote state backends.
|
|
|
|
//
|
|
|
|
// All exported fields should be set. This struct should only be used
|
|
|
|
// by implementers of backends, not by consumers. If you're consuming, please
|
|
|
|
// use a higher level package such as Consul backends.
|
|
|
|
type Backend struct {
|
|
|
|
// Backend should be set to the configuration schema. ConfigureFunc
|
|
|
|
// should not be set on the schema.
|
|
|
|
*schema.Backend
|
|
|
|
|
|
|
|
// ConfigureFunc takes the ctx from a schema.Backend and returns a
|
|
|
|
// fully configured remote client to use for state operations.
|
|
|
|
ConfigureFunc func(ctx context.Context) (remote.Client, error)
|
|
|
|
|
|
|
|
client remote.Client
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
func (b *Backend) Configure(obj cty.Value) tfdiags.Diagnostics {
|
|
|
|
|
2017-01-19 05:49:01 +01:00
|
|
|
// Set our configureFunc manually
|
|
|
|
b.Backend.ConfigureFunc = func(ctx context.Context) error {
|
|
|
|
c, err := b.ConfigureFunc(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the client for later
|
|
|
|
b.client = c
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:43:02 +01:00
|
|
|
return b.Backend.Configure(obj)
|
2017-01-19 05:49:01 +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
|
|
|
func (b *Backend) Workspaces() ([]string, error) {
|
2017-02-27 22:56:55 +01:00
|
|
|
return nil, backend.ErrNamedStatesNotSupported
|
2017-02-21 16:48:00 +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
|
|
|
func (b *Backend) DeleteWorkspace(name string) error {
|
2017-02-27 22:56:55 +01:00
|
|
|
return backend.ErrNamedStatesNotSupported
|
2017-02-21 16:48:00 +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
|
|
|
func (b *Backend) StateMgr(name string) (statemgr.Full, error) {
|
2017-01-19 05:49:01 +01:00
|
|
|
// This shouldn't happen
|
|
|
|
if b.client == nil {
|
|
|
|
panic("nil remote client")
|
|
|
|
}
|
|
|
|
|
2017-02-27 22:56:55 +01:00
|
|
|
if name != backend.DefaultStateName {
|
|
|
|
return nil, backend.ErrNamedStatesNotSupported
|
|
|
|
}
|
|
|
|
|
2017-01-19 05:49:01 +01:00
|
|
|
s := &remote.State{Client: b.client}
|
|
|
|
return s, nil
|
|
|
|
}
|