Working with Terraform Workspaces


When we’re setting up infrastructure, we’re often required to create similar resources in various environments but with slightly different modifications. We can decide to create multiple directories to hold the configuration files for each environment. For example, we can create three directories named development, staging, and production which will hold configuration files and state files for the development, staging, and production environment.

A better approach to managing our configurations for each environment is by using Terraform workspaces. With workspaces, we can have multiple infrastructure configurations in a single directory. Each workspace has its own state file, which allows us to apply changes to a specific environment without affecting others.

Get hands-on with 1200+ tech skills courses.