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.
This commit is contained in:
parent
e5900a36a6
commit
88d8d5e6ee
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue