Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a Terraform workspace?
A Terraform workspace is like a separate environment where you can manage different versions of your infrastructure independently, similar to having different folders for different projects.
Click to reveal answer
beginner
How do you create a new workspace in Terraform?
Use the command terraform workspace new <workspace_name> to create a new workspace.
Click to reveal answer
beginner
How can you switch to an existing workspace?
Use terraform workspace select <workspace_name> to switch to an existing workspace.
Click to reveal answer
beginner
What command lists all available Terraform workspaces?
Use terraform workspace list to see all workspaces in your current Terraform project.
Click to reveal answer
intermediate
Why use Terraform workspaces instead of separate projects?
Workspaces let you manage multiple environments (like dev, test, prod) in the same project without copying files, making it easier to keep infrastructure consistent and organized.
Click to reveal answer
Which command creates a new Terraform workspace?
Aterraform workspace new myworkspace
Bterraform workspace select myworkspace
Cterraform init myworkspace
Dterraform apply myworkspace
✗ Incorrect
The command terraform workspace new <name> creates a new workspace.
How do you switch to an existing workspace named 'test'?
Aterraform workspace new test
Bterraform workspace select test
Cterraform switch test
Dterraform workspace use test
✗ Incorrect
Use terraform workspace select test to switch to the 'test' workspace.
What does terraform workspace list show?
AAll Terraform projects on your machine
BAll Terraform versions installed
CAll workspaces in the current Terraform project
DAll resources in the current workspace
✗ Incorrect
It lists all workspaces available in the current Terraform project.
Why might you use workspaces in Terraform?
ATo speed up Terraform apply
BTo write code faster
CTo store secrets securely
DTo manage multiple environments like dev and prod separately
✗ Incorrect
Workspaces help manage different environments independently within the same project.
What happens if you run terraform workspace select with a workspace name that does not exist?
ATerraform returns an error
BTerraform switches to the default workspace
CTerraform creates the workspace automatically
DTerraform deletes the current workspace
✗ Incorrect
Terraform returns an error because the workspace does not exist.
Explain how to create and switch between Terraform workspaces.
Think of workspaces as separate folders for different environments.
You got /3 concepts.
Describe why using Terraform workspaces can be helpful in managing infrastructure.
Imagine managing different rooms in the same house instead of building new houses.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of Terraform workspaces?
easy
A. To separate different infrastructure environments
B. To store Terraform state files locally
C. To create new Terraform modules
D. To manage user permissions
Solution
Step 1: Understand workspace concept
Terraform workspaces allow you to manage multiple distinct environments like development and production within the same configuration.
Step 2: Identify the purpose
Separating infrastructure environments helps avoid conflicts and keeps states isolated.
Final Answer:
To separate different infrastructure environments -> Option A
Quick Check:
Workspaces separate environments = A [OK]
Hint: Workspaces isolate environments like folders for projects [OK]
Common Mistakes:
Confusing workspaces with modules
Thinking workspaces manage permissions
Believing workspaces store files locally only
2. Which command correctly creates a new workspace named staging?
easy
A. terraform workspace create staging
B. terraform workspace new staging
C. terraform workspace add staging
D. terraform workspace select staging
Solution
Step 1: Recall workspace creation syntax
The correct command to create a new workspace is terraform workspace new <name>.
Step 2: Match the command to the option
terraform workspace new staging uses terraform workspace new staging, which is correct.
Final Answer:
terraform workspace new staging -> Option B
Quick Check:
Create workspace = terraform workspace new [OK]
Hint: Use 'terraform workspace new' to create workspaces [OK]
Common Mistakes:
Using 'create' instead of 'new'
Using 'add' which is invalid
Confusing 'select' with creation
3. Given the commands:
terraform workspace new test-env
tf workspace select test-env
tf workspace show
What will be the output of terraform workspace show?
medium
A. test-env
B. Error: workspace not found
C. No workspace selected
D. default
Solution
Step 1: Analyze command correctness
The first command terraform workspace new test-env is correct and creates the workspace 'test-env'.
Step 2: Identify invalid commands
The next two commands use the alias tf instead of terraform, which will cause errors unless 'tf' is defined as an alias.
Step 3: Determine output of terraform workspace show
Since tf workspace select test-env likely fails, the workspace is not switched, so terraform workspace show will output the current workspace, which remains default.
Final Answer:
default -> Option D
Quick Check:
Invalid alias causes select to fail, so workspace remains default [OK]
Hint: Use full 'terraform' command unless alias is defined [OK]
Common Mistakes:
Assuming 'tf' alias works by default
Expecting workspace switch without correct command
Ignoring command syntax errors
4. You run terraform workspace select prod but get an error: Workspace 'prod' does not exist. What should you do to fix this?
medium
A. Run terraform workspace new prod to create it first
B. Run terraform init to initialize the workspace
C. Delete the default workspace and retry
D. Run terraform workspace list to delete 'prod'
Solution
Step 1: Understand the error
The error means the workspace 'prod' does not exist yet, so it cannot be selected.
Step 2: Create the missing workspace
You must create it first using terraform workspace new prod before selecting it.
Final Answer:
Run terraform workspace new prod to create it first -> Option A
Quick Check:
Select workspace requires existing workspace [OK]
Hint: Create workspace before selecting it [OK]
Common Mistakes:
Trying to select without creating
Running init instead of new
Deleting default workspace unnecessarily
5. You want to maintain separate Terraform states for dev and prod environments using workspaces. Which sequence of commands correctly sets this up and switches to prod?
hard
A. terraform workspace new prod terraform workspace select dev
B. terraform workspace select dev terraform workspace select prod
C. terraform workspace new dev terraform workspace new prod terraform workspace select prod
D. terraform workspace new dev terraform workspace select dev terraform workspace new prod
Solution
Step 1: Create both workspaces
Use terraform workspace new dev and terraform workspace new prod to create separate environments.
Step 2: Switch to the desired workspace
Use terraform workspace select prod to switch to the production environment.
Final Answer:
terraform workspace new dev terraform workspace new prod terraform workspace select prod -> Option C
Quick Check:
Create then select workspace sequence [OK]
Hint: Create all workspaces before selecting one [OK]