Merge pull request #8647 from hashicorp/f-local-remote-state

state/remote: Officially Support local backend
This commit is contained in:
James Nugent 2016-09-03 15:47:07 -07:00 committed by GitHub
commit f1aecc158e
5 changed files with 60 additions and 7 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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,
}

View File

@ -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.

View File

@ -34,6 +34,9 @@
<li<%= sidebar_current("docs-state-remote-http") %>>
<a href="/docs/state/remote/http.html">http</a>
</li>
<li<%= sidebar_current("docs-state-remote-local") %>>
<a href="/docs/state/remote/local.html">local</a>
</li>
<li<%= sidebar_current("docs-state-remote-s3") %>>
<a href="/docs/state/remote/s3.html">s3</a>
</li>