0
0
Terraformcloud~10 mins

Workspace naming conventions in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Workspace naming conventions
Start: Need to create workspace
Choose naming pattern
Apply naming rules
Create workspace with name
Use workspace in terraform commands
Manage infrastructure per workspace
End
This flow shows how to pick and apply a naming pattern to create and use Terraform workspaces consistently.
Execution Sample
Terraform
terraform workspace new dev-us-east-1
terraform workspace select dev-us-east-1
terraform apply
Create and select a workspace named 'dev-us-east-1' following naming conventions, then apply infrastructure changes.
Process Table
StepActionWorkspace NameNaming Rule AppliedResult
1Create workspacedev-us-east-1env-region formatWorkspace 'dev-us-east-1' created
2Select workspacedev-us-east-1matches existing workspaceWorkspace 'dev-us-east-1' selected
3Apply terraformdev-us-east-1workspace used for state isolationInfrastructure applied in 'dev-us-east-1' workspace
4Create workspaceprod-eu-west-2env-region formatWorkspace 'prod-eu-west-2' created
5Select workspaceprod-eu-west-2matches existing workspaceWorkspace 'prod-eu-west-2' selected
6Apply terraformprod-eu-west-2workspace used for state isolationInfrastructure applied in 'prod-eu-west-2' workspace
7Attempt create workspacedefaultreserved nameError: invalid workspace name
8Attempt create workspacetesttoo generic, no regionWarning: naming convention not followed
9End--Workspaces created and used following naming conventions
💡 Execution stops after creating and using valid workspaces and showing errors for invalid names.
Status Tracker
VariableStartAfter Step 1After Step 4After Step 7Final
workspace_name-dev-us-east-1prod-eu-west-2default (invalid)-
Key Moments - 3 Insights
Why can't I use the name 'default' for a workspace?
'default' is a reserved name in Terraform. Step 7 shows an error when trying to create it.
What happens if I use a generic name like 'test'?
Step 8 shows a warning because 'test' does not follow the recommended env-region pattern, which helps organize workspaces clearly.
Why do we include region in the workspace name?
Including region (like 'us-east-1') helps separate infrastructure states by location, as seen in steps 1 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what workspace name was successfully created in step 4?
ADev_US_East_1
Bdev-us-east-1
Cprod-eu-west-2
Dtest
💡 Hint
Check the 'Workspace Name' column in row for step 4.
At which step does Terraform reject a workspace name?
AStep 7
BStep 4
CStep 1
DStep 8
💡 Hint
Look for the row with 'Error: invalid workspace name' in the 'Result' column.
If you omit the region in the workspace name, what is the likely outcome according to the table?
AWorkspace creation succeeds with no warnings
BWorkspace creation succeeds but with a warning
CWorkspace creation fails with error
DTerraform automatically adds the region
💡 Hint
See step 8 where 'test' workspace is created with a warning.
Concept Snapshot
Terraform workspace names should be lowercase, use hyphens, and follow env-region pattern.
Example: dev-us-east-1
This helps isolate infrastructure states by environment and region.
Invalid names cause errors; generic names cause warnings.
Use 'terraform workspace new <name>' to create and 'terraform workspace select <name>' to switch.
Full Transcript
This visual execution shows how Terraform workspace naming conventions work. We start by choosing a naming pattern that includes environment and region, like 'dev-us-east-1'. We create and select workspaces with these names. The execution table shows successful creation and selection of valid names, and errors or warnings when names don't follow rules. Variables track the workspace name changes. Key moments clarify why lowercase and hyphens are required, why including region matters, and why generic names cause warnings. The quiz tests understanding of these steps. The snapshot summarizes the naming rules and commands.