From 5c58ef16f7b57784e1be810364566ae4236ccf48 Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Tue, 5 Dec 2017 10:18:28 -0800 Subject: [PATCH] provider/terraform: deprecate "environment" in favor of "workspace" --- .../providers/terraform/data_source_state.go | 17 ++++++++++++++--- .../providers/terraform/d/remote_state.html.md | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/builtin/providers/terraform/data_source_state.go b/builtin/providers/terraform/data_source_state.go index 9cb39d0eaf..1f0fbea483 100644 --- a/builtin/providers/terraform/data_source_state.go +++ b/builtin/providers/terraform/data_source_state.go @@ -43,6 +43,13 @@ func dataSourceRemoteState() *schema.Resource { }, "environment": { + Type: schema.TypeString, + Optional: true, + Default: backend.DefaultStateName, + Deprecated: "Terraform environments are now called workspaces. Please use the workspace key instead.", + }, + + "workspace": { Type: schema.TypeString, Optional: true, Default: backend.DefaultStateName, @@ -84,9 +91,13 @@ func dataSourceRemoteStateRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error initializing backend: %s", err) } - // Get the state - env := d.Get("environment").(string) - state, err := b.State(env) + // environment is deprecated in favour of workspace. + // If both keys are set workspace should win. + name := d.Get("environment").(string) + if ws, ok := d.GetOk("workspace"); ok { + name = ws.(string) + } + state, err := b.State(name) if err != nil { return fmt.Errorf("error loading the remote state: %s", err) } diff --git a/website/docs/providers/terraform/d/remote_state.html.md b/website/docs/providers/terraform/d/remote_state.html.md index 1385709224..d315073399 100644 --- a/website/docs/providers/terraform/d/remote_state.html.md +++ b/website/docs/providers/terraform/d/remote_state.html.md @@ -31,7 +31,7 @@ resource "aws_instance" "foo" { The following arguments are supported: * `backend` - (Required) The remote backend to use. -* `environment` - (Optional) The Terraform environment to use. +* `workspace` - (Optional) The Terraform workspace to use. * `config` - (Optional) The configuration of the remote backend. * `defaults` - (Optional) default value for outputs in case state file is empty or it does not have the output. * Remote state config docs can be found [here](/docs/backends/types/terraform-enterprise.html)