Bird
Raised Fist0
Terraformcloud~20 mins

Default workspace in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
Terraform Workspace Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform Default Workspace Behavior

What is the default workspace name when you initialize a new Terraform configuration without creating any additional workspaces?

Aterraform
Bmain
Cdefault
Dprod
Attempts:
2 left
💡 Hint

Think about the workspace Terraform uses if you never switch or create a new one.

service_behavior
intermediate
2:00remaining
Effect of Workspace on Terraform State Files

When you switch from the default workspace to a new workspace named dev, what happens to the Terraform state files?

ATerraform creates a separate state file for the <code>dev</code> workspace.
BTerraform merges the <code>dev</code> workspace state with the default workspace state file.
CTerraform overwrites the existing default workspace state file with the <code>dev</code> workspace state.
DTerraform deletes the default workspace state file.
Attempts:
2 left
💡 Hint

Think about how Terraform isolates environments using workspaces.

Architecture
advanced
3:00remaining
Workspace Usage in Multi-Environment Terraform Architecture

You want to manage production and staging environments using Terraform workspaces. Which approach correctly uses workspaces to separate these environments?

ACreate separate Terraform configurations for production and staging without using workspaces.
BCreate two workspaces named <code>production</code> and <code>staging</code>, and switch between them to apply changes to each environment.
CUse the default workspace for production and create a <code>staging</code> workspace for staging environment.
DUse one workspace and manage both environments by passing different variables during apply.
Attempts:
2 left
💡 Hint

Workspaces are designed to isolate state for different environments.

security
advanced
3:00remaining
Security Implications of Using Default Workspace

What is a potential security risk of using the default workspace for multiple environments in Terraform?

AState files for different environments can overwrite each other, leading to accidental resource changes.
BDefault workspace encrypts state files with weak encryption.
CDefault workspace automatically exposes state files publicly.
DDefault workspace disables Terraform state locking.
Attempts:
2 left
💡 Hint

Consider what happens if multiple environments share the same state file.

Best Practice
expert
4:00remaining
Best Practice for Managing Terraform Workspaces in Team Environments

In a team environment, what is the best practice to manage Terraform workspaces to avoid conflicts and ensure smooth collaboration?

AUse the default workspace only and manually rename state files to separate environments.
BEach team member uses their own local default workspace without sharing state remotely.
CAvoid using workspaces and manage environments by duplicating Terraform code for each environment.
DUse remote backend with workspace support and enforce workspace naming conventions for each environment.
Attempts:
2 left
💡 Hint

Think about how teams can share state safely and avoid conflicts.

Practice

(1/5)
1. What is the default workspace in Terraform?
easy
A. A workspace only for remote backends
B. A workspace you must create manually before use
C. A temporary workspace that deletes after each run
D. The main workspace Terraform uses automatically to store state

Solution

  1. Step 1: Understand Terraform workspaces

    Terraform uses workspaces to manage different states. The default workspace is created automatically.
  2. Step 2: Identify the role of the default workspace

    The default workspace stores the state unless you create and switch to others.
  3. Final Answer:

    The main workspace Terraform uses automatically to store state -> Option D
  4. Quick Check:

    Default workspace = main automatic workspace [OK]
Hint: Default workspace is automatic and stores state by default [OK]
Common Mistakes:
  • Thinking default workspace must be created manually
  • Assuming default workspace deletes after runs
  • Confusing default workspace with remote backend only
2. Which command shows the current active workspace in Terraform?
easy
A. terraform workspace list
B. terraform workspace show
C. terraform workspace current
D. terraform workspace status

Solution

  1. Step 1: Recall Terraform workspace commands

    Common commands include list to see all workspaces and show to display the current one.
  2. Step 2: Identify the command to show active workspace

    terraform workspace show outputs the current active workspace name.
  3. Final Answer:

    terraform workspace show -> Option B
  4. Quick Check:

    Show current workspace = terraform workspace show [OK]
Hint: Use 'terraform workspace show' to see active workspace [OK]
Common Mistakes:
  • Using 'terraform workspace list' to show current workspace
  • Assuming 'terraform workspace current' is valid
  • Confusing 'status' with workspace commands
3. Given this Terraform CLI output after running terraform workspace list:

  default
* dev
  staging
Which workspace is currently active?
medium
A. default
B. staging
C. dev
D. No workspace is active

Solution

  1. Step 1: Understand workspace list output format

    The asterisk (*) marks the currently active workspace in the list.
  2. Step 2: Identify the active workspace

    The workspace with * is dev, so it is active.
  3. Final Answer:

    dev -> Option C
  4. Quick Check:

    Asterisk marks active workspace = dev [OK]
Hint: Look for * in workspace list to find active workspace [OK]
Common Mistakes:
  • Choosing 'default' because it sounds like default
  • Ignoring the asterisk symbol
  • Assuming no workspace is active if not obvious
4. You run terraform workspace new test but get an error: "Workspace 'test' already exists." What should you do next?
medium
A. Run terraform workspace select test to switch to it
B. Delete the existing workspace with terraform workspace delete test
C. Rename the existing workspace before creating a new one
D. Run terraform init again to fix the error

Solution

  1. Step 1: Understand the error message

    The error says the workspace already exists, so you cannot create it again.
  2. Step 2: Choose the correct action

    Since it exists, you should switch to it using terraform workspace select test.
  3. Final Answer:

    Run terraform workspace select test to switch to it -> Option A
  4. Quick Check:

    Workspace exists? Select it, don't create [OK]
Hint: Select existing workspace instead of creating it again [OK]
Common Mistakes:
  • Trying to create workspace again without switching
  • Deleting workspace unnecessarily
  • Running init does not fix workspace existence
5. You want to manage two environments, prod and dev, using Terraform workspaces. Which approach correctly uses the default workspace?
hard
A. Use default workspace for dev and create/select prod workspace
B. Create both prod and dev workspaces and never use default
C. Rename default workspace to prod and create dev workspace
D. Use the default workspace for prod and create/select dev workspace

Solution

  1. Step 1: Understand default workspace role

    The default workspace is ready to use and often used for simpler or initial environments.
  2. Step 2: Apply best practice for environment separation

    Use default for dev (development) and create/select a separate workspace for prod (production) to isolate states.
  3. Final Answer:

    Use default workspace for dev and create/select prod workspace -> Option A
  4. Quick Check:

    Default workspace = dev environment [OK]
Hint: Use default for dev, create prod workspace for safety [OK]
Common Mistakes:
  • Using default for prod which risks accidental changes
  • Ignoring default workspace and creating all manually
  • Trying to rename default workspace (not supported)