Bird
Raised Fist0
Terraformcloud~5 mins

Default workspace in Terraform - Cheat Sheet & Quick Revision

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
Recall & Review
beginner
What is the default workspace in Terraform?
The default workspace is the initial workspace Terraform creates automatically. It holds the state for your infrastructure unless you create and switch to other workspaces.
Click to reveal answer
beginner
How does the default workspace relate to Terraform state files?
The default workspace stores its state in the main state file (usually terraform.tfstate). Other workspaces have separate state files.
Click to reveal answer
intermediate
Can you rename or delete the default workspace in Terraform?
No, the default workspace cannot be renamed or deleted. It always exists as the base workspace.
Click to reveal answer
beginner
How do you switch from the default workspace to another workspace?
Use the command terraform workspace select <workspace-name> to switch from the default workspace to another existing workspace.
Click to reveal answer
intermediate
Why use multiple workspaces instead of just the default workspace?
Multiple workspaces let you manage different environments (like dev, test, prod) with separate states, avoiding conflicts and making management easier.
Click to reveal answer
What is the name of the initial workspace Terraform creates by default?
Adefault
Bmain
Cbase
Dprimary
Can you delete the default workspace in Terraform?
ANo, it always exists
BOnly if no resources exist
CYes, anytime
DOnly with special permissions
Which command switches to a different workspace?
Aterraform workspace new
Bterraform workspace init
Cterraform workspace select
Dterraform workspace delete
Where does the default workspace store its state?
AIn a separate file per workspace
BIn the main terraform.tfstate file
CIn the cloud only
DIt does not store state
Why might you create multiple workspaces instead of using only the default?
ATo avoid using state files
BTo speed up Terraform runs
CTo reduce Terraform file size
DTo manage different environments separately
Explain what the default workspace is and its role in Terraform state management.
Think about how Terraform keeps track of your infrastructure by default.
You got /4 concepts.
    Describe how and why you would use multiple workspaces instead of just the default workspace.
    Consider managing dev, test, and prod environments.
    You got /4 concepts.

      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)