provider/terraform: deprecate "environment" in favor of "workspace"

This commit is contained in:
Nic Cope 2017-12-05 10:18:28 -08:00 committed by Martin Atkins
parent 03c123e39d
commit 5c58ef16f7
2 changed files with 15 additions and 4 deletions

View File

@ -46,6 +46,13 @@ func dataSourceRemoteState() *schema.Resource {
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,
},
"__has_dynamic_attributes": {
@ -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)
}

View File

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