Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend configuration should support workspaces #23874

Open
matti opened this issue Jan 16, 2020 · 5 comments
Open

backend configuration should support workspaces #23874

matti opened this issue Jan 16, 2020 · 5 comments

Comments

@matti
Copy link

matti commented Jan 16, 2020

currently it's not possible to have backend per workspace.

for example workspace "bar" to have bucket "terraform-bar" and "beer" to have bucket "terraform-beer"

both workspaces live in the same bucket, effectively granting user access to all workspaces.

this is due to .terraform/terraform.tfstate not supporting workspaces.

proposed solution: use .terraform/<workspacename>.tfstate when workspace configured.

@matti matti changed the title backend configuration should support workspace backend configuration should support workspaces Jan 16, 2020
@jbardin
Copy link
Member

jbardin commented Jan 22, 2020

Hi @matti,

You mention "bucket" in the issue here, is this a specific request for the s3 backend?
Workspaces as they are implemented now live within a backend, and therefore any options would need to be configured by a particular backend depending on what it could support. There will likely be reconsideration of what workspaces in the CLI mean in the future, but that would be separate from a feature request for for a remote state backend.

The .terraform/terraform.tfstate file itself is only storage for the init configuration, and doesn't apply to workspaces.

@jbardin jbardin added the waiting-response An issue/pull request is waiting for a response from the community label Jan 22, 2020
@matti
Copy link
Author

matti commented Jan 23, 2020

I think that the following workaround would work:

TF_DATA_DIR
By default this data is written into a .terraform subdirectory of the current directory, but the path given in TF_DATA_DIR will be used instead if non-empty.

export TF_WORKSPACE=bar
export TF_DATA_DIR=.terraform-$TF_WORKSPACE
terraform apply

this would keep init configurations separate and per workspace

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Jan 23, 2020
@jbardin
Copy link
Member

jbardin commented Jan 23, 2020

Thanks @matti

I think this is confusion abut what workspaces are in the CLI, and why I mentioned that we have plans to rethink this to better align them with "workspaces" in Terraform Cloud which are different.

In the CLI, workspaces are simply a named state file, and switching workspaces only changes which name the state goes by within the current backend. Because they only exist within the backend itself, you need to start with the same TF_DATA_DIR.

@hashibot hashibot added the cli label Jan 23, 2020
@matti
Copy link
Author

matti commented Jan 31, 2020

Confusion or not, I'm now sucessfully running TF_DATA_DIR set to .terraformhack/$TF_WORKSPACE and configuring bucket with init options.

This allows concurrent running of different workspaces at the same time from my machine.

@matti
Copy link
Author

matti commented Jan 31, 2020

so technically I'm not using multiple workspaces at the same time - I only use them to get handy terraform.workspace without having to declare something like var.name in every module etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants