workspace
What is workspace?
workspace: Named state instances within one backend, letting you reuse a config for dev/staging/prod with separate state. Terraform workspaces let one configuration manage several separate states in the same backend, such as default, staging and production. terraform workspace select staging switches which state you are working on. Inside the configuration, terraform.workspace returns the current name, so you can adjust sizes or names per environment.
Frequently asked questions about workspace
What should you keep in mind with workspace?
Workspaces are convenient but easy to misuse. It is simple to apply to production while thinking you are in staging, because nothing in the code itself shows the difference. Many teams prefer separate folders or separate backend configurations per environment, which make the target explicit and allow different permissions. If you use workspaces, show the current one in your shell prompt and in CI logs.
What does an example of workspace look like?
terraform workspace new staging terraform workspace select staging At a glance
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |