From 8d0a68e1d44fe2e79c5b56c643aac59ea087efa6 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Sat, 3 Sep 2016 15:38:43 -0700 Subject: [PATCH] state/remote: Officially Support local backend This is a rework of pull request #6213 submitted by @joshuaspence, adjusted to work with the remote state data source. We also add a deprecation warning for people using the unsupported API, and retain the ability to refer to "_local" as well as "local" for users in a mixed version environment. --- .../providers/terraform/data_source_state.go | 16 +++++++++ .../terraform/data_source_state_test.go | 6 ++-- state/remote/remote.go | 6 ++-- .../source/docs/state/remote/local.html.md | 36 +++++++++++++++++++ website/source/layouts/remotestate.erb | 3 ++ 5 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 website/source/docs/state/remote/local.html.md diff --git a/builtin/providers/terraform/data_source_state.go b/builtin/providers/terraform/data_source_state.go index c87da01fb..2c3c5b050 100644 --- a/builtin/providers/terraform/data_source_state.go +++ b/builtin/providers/terraform/data_source_state.go @@ -16,6 +16,16 @@ func dataSourceRemoteState() *schema.Resource { "backend": { Type: schema.TypeString, Required: true, + ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { + if vStr, ok := v.(string); ok && vStr == "_local" { + ws = append(ws, "Use of the %q backend is now officially "+ + "supported as %q. Please update your configuration to ensure "+ + "compatibility with future versions of Terraform.", + "_local", "local") + } + + return + }, }, "config": { @@ -38,6 +48,12 @@ func dataSourceRemoteStateRead(d *schema.ResourceData, meta interface{}) error { config[k] = v.(string) } + // Don't break people using the old _local syntax - but note warning above + if backend == "_local" { + log.Println(`[INFO] Switching old (unsupported) backend "_local" to "local"`) + backend = "local" + } + // Create the client to access our remote state log.Printf("[DEBUG] Initializing remote state client: %s", backend) client, err := remote.NewClient(backend, config) diff --git a/builtin/providers/terraform/data_source_state_test.go b/builtin/providers/terraform/data_source_state_test.go index 0bab4b261..1d56823ef 100644 --- a/builtin/providers/terraform/data_source_state_test.go +++ b/builtin/providers/terraform/data_source_state_test.go @@ -32,7 +32,7 @@ func TestState_complexOutputs(t *testing.T) { { Config: testAccState_complexOutputs, Check: resource.ComposeTestCheckFunc( - testAccCheckStateValue("terraform_remote_state.foo", "backend", "_local"), + testAccCheckStateValue("terraform_remote_state.foo", "backend", "local"), testAccCheckStateValue("terraform_remote_state.foo", "config.path", "./test-fixtures/complex_outputs.tfstate"), testAccCheckStateValue("terraform_remote_state.foo", "computed_set.#", "2"), testAccCheckStateValue("terraform_remote_state.foo", `map.%`, "2"), @@ -65,7 +65,7 @@ func testAccCheckStateValue(id, name, value string) resource.TestCheckFunc { const testAccState_basic = ` data "terraform_remote_state" "foo" { - backend = "_local" + backend = "local" config { path = "./test-fixtures/basic.tfstate" @@ -74,7 +74,7 @@ data "terraform_remote_state" "foo" { const testAccState_complexOutputs = ` resource "terraform_remote_state" "foo" { - backend = "_local" + backend = "local" config { path = "./test-fixtures/complex_outputs.tfstate" diff --git a/state/remote/remote.go b/state/remote/remote.go index fdec41bcc..173ab00ca 100644 --- a/state/remote/remote.go +++ b/state/remote/remote.go @@ -36,16 +36,14 @@ func NewClient(t string, conf map[string]string) (Client, error) { // BuiltinClients is the list of built-in clients that can be used with // NewClient. var BuiltinClients = map[string]Factory{ + "artifactory": artifactoryFactory, "atlas": atlasFactory, "azure": azureFactory, "consul": consulFactory, "etcd": etcdFactory, "gcs": gcsFactory, "http": httpFactory, + "local": fileFactory, "s3": s3Factory, "swift": swiftFactory, - "artifactory": artifactoryFactory, - - // This is used for development purposes only. - "_local": fileFactory, } diff --git a/website/source/docs/state/remote/local.html.md b/website/source/docs/state/remote/local.html.md new file mode 100644 index 000000000..b8495a2f5 --- /dev/null +++ b/website/source/docs/state/remote/local.html.md @@ -0,0 +1,36 @@ +--- +layout: "remotestate" +page_title: "Remote State Backend: local" +sidebar_current: "docs-state-remote-local" +description: |- + Remote state stored using the local file system. +--- + +# local + +Remote state backend that uses the local file system. + +## Example Usage + +``` +terraform remote config \ + -backend=local \ + -backend-config="path=/path/to/terraform.tfstate" +``` + +## Example Reference + +``` +data "terraform_remote_state" "foo" { + backend = "local" + config { + path = "${path.module}/../../terraform.tfstate" + } +} +``` + +## Configuration variables + +The following configuration options are supported: + + * `path` - (Required) The path to the `tfstate` file. diff --git a/website/source/layouts/remotestate.erb b/website/source/layouts/remotestate.erb index cd14b9d77..3a3a27cbb 100644 --- a/website/source/layouts/remotestate.erb +++ b/website/source/layouts/remotestate.erb @@ -34,6 +34,9 @@ > http + > + local + > s3