1

I'm having a bit of trouble with Terraform. I have a Terraform project which is shared by a few developers and uses non-default workspaces (i.e. named workspaces, not the default one). I would like all the developers to share access to the Terraform state of this shared workspace the same way as if it was the default workspace. I have set up remote state with S3, so the state file is singleton, but for some reason I can't get the remote state file to be recognized on each developer's machine.

Basically the workflow I would like is, when developer A pushes a change to Terraform (using terraform apply) then any other developer who runs terraform state list should see that change reflected in the deployed infra, and that this workflow should work for any workspace, not only the default workspace.

How do I accomplish this?

1

As the docs state, workspaces are for distinct resources:

Named workspaces allow conveniently switching between multiple instances of a single configuration within its single backend. They are convenient in a number of situations, but cannot solve all problems.

A common use for multiple workspaces is to create a parallel, distinct copy of a set of infrastructure in order to test a set of changes before modifying the main production infrastructure. For example, a developer working on a complex set of infrastructure changes might create a new temporary workspace in order to freely experiment with changes without affecting the default workspace.

If you would like all developers to see the same state, they have to use the same workspace. If you want this to be the case for arbitrary workspaces, then it seems that this is an abuse of the concept of the workspace. It is possible, but I would strongly advise against it, to import resources from non-default workspaces into the default one, in some kind of automated way. You could also use the default workspace state as the non-default's remote state, but again, I would strongly advise against this, arguing that it introduces unnecessary complexity and fragility to your process.

If you want all developers to see the same resources in the state, then they should simply all use the same workspace. If they are not seeing the correct state, it is because the workspace or the remote state location that they are using is different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.