Bird
Raised Fist0
Terraformcloud~10 mins

Workspace naming conventions in Terraform - Interactive Code Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the Terraform workspace name to "production".

Terraform
terraform workspace select [1]
Drag options to blanks, or click blank then click option'
Aproduction
Btest
Cdevelopment
Dstaging
Attempts:
3 left
💡 Hint
Common Mistakes
Using a workspace name that does not exist.
Including quotes around the workspace name.
2fill in blank
medium

Complete the code to create a new Terraform workspace named "staging".

Terraform
terraform workspace [1] staging
Drag options to blanks, or click blank then click option'
Acreate
Bnew
Cselect
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'create'.
Trying to select a workspace before it exists.
3fill in blank
hard

Fix the error in the command to switch to the "dev" workspace.

Terraform
terraform workspace [1] dev
Drag options to blanks, or click blank then click option'
Acreate
Bselect
Cinit
Dapply
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' instead of 'select' to switch workspaces.
Using 'init' which initializes Terraform but does not switch workspaces.
4fill in blank
hard

Fill both blanks to list all Terraform workspaces and then switch to the "test" workspace.

Terraform
terraform workspace [1]
terraform workspace [2] test
Drag options to blanks, or click blank then click option'
Alist
Bselect
Ccreate
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' instead of 'list' to show workspaces.
Using 'init' which does not list or select workspaces.
5fill in blank
hard

Fill all three blanks to create a new workspace named "qa", switch to it, and then show the current workspace.

Terraform
terraform workspace [1] qa
terraform workspace [2] qa
terraform workspace [3]
Drag options to blanks, or click blank then click option'
Anew
Bselect
Cshow
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' instead of 'show' to display current workspace.
Switching workspace before creating it.

Practice

(1/5)
1.

What is the main purpose of using workspace names in Terraform?

easy
A. To store Terraform code files
B. To organize different environments like development and production
C. To define cloud provider credentials
D. To create virtual machines automatically

Solution

  1. Step 1: Understand workspace role

    Workspaces in Terraform separate different environments or states, like dev and prod.
  2. Step 2: Match purpose to options

    Only To organize different environments like development and production describes organizing environments, which is the workspace's main use.
  3. Final Answer:

    To organize different environments like development and production -> Option B
  4. Quick Check:

    Workspace names = environment organization [OK]
Hint: Workspaces separate environments, not code or credentials [OK]
Common Mistakes:
  • Confusing workspace with code storage
  • Thinking workspace manages credentials
  • Assuming workspace creates resources directly
2.

Which of the following workspace names follows best naming conventions in Terraform?

terraform workspace new ?
easy
A. staging-1
B. dev_environment
C. Prod-Env
D. TestEnv

Solution

  1. Step 1: Review naming rules

    Best practice is lowercase letters, hyphens allowed, no underscores or uppercase.
  2. Step 2: Check each option

    staging-1 uses lowercase and hyphen, fitting the rules. Others use uppercase or underscores.
  3. Final Answer:

    staging-1 -> Option A
  4. Quick Check:

    Lowercase + hyphen = staging-1 [OK]
Hint: Use lowercase and hyphens, avoid underscores and capitals [OK]
Common Mistakes:
  • Using uppercase letters
  • Using underscores instead of hyphens
  • Including spaces or special characters
3.

What will happen if you run the command terraform workspace select prod-env but the workspace prod-env does not exist?

medium
A. Terraform shows an error saying workspace not found
B. Terraform deletes the current workspace
C. Terraform switches to the default workspace
D. Terraform creates a new workspace named prod-env automatically

Solution

  1. Step 1: Understand workspace select behavior

    The select command switches to an existing workspace; it does not create one.
  2. Step 2: Check command outcome

    If the workspace does not exist, Terraform returns an error message.
  3. Final Answer:

    Terraform shows an error saying workspace not found -> Option A
  4. Quick Check:

    Select non-existent workspace = error [OK]
Hint: Select only switches; create with 'terraform workspace new' [OK]
Common Mistakes:
  • Assuming select creates workspace
  • Thinking Terraform switches to default silently
  • Believing workspace gets deleted
4.

Identify the error in this workspace creation command:

terraform workspace new Dev_Env
medium
A. Workspace names cannot contain uppercase letters
B. Workspace names must start with a number
C. Workspace names must be longer than 10 characters
D. Workspace names cannot contain underscores

Solution

  1. Step 1: Check naming rules for characters

    Workspace names should use lowercase letters and hyphens; underscores are not recommended.
  2. Step 2: Analyze the command

    The name 'Dev_Env' contains an underscore, which breaks the naming convention.
  3. Final Answer:

    Workspace names cannot contain underscores -> Option D
  4. Quick Check:

    Underscores disallowed in workspace names [OK]
Hint: Avoid underscores; use hyphens instead [OK]
Common Mistakes:
  • Thinking uppercase letters are forbidden (they are discouraged but allowed)
  • Believing names must start with numbers
  • Assuming length restrictions apply
5.

You want to create workspaces for three environments: development, testing, and production. Which set of workspace names follows best practices for naming conventions?

hard
A. dev, test_env, production
B. development, testing, production
C. dev-01, test-01, prod-01
D. Dev, Test, Prod

Solution

  1. Step 1: Review naming best practices

    Use lowercase letters, hyphens allowed, no underscores or uppercase letters.
  2. Step 2: Evaluate each option

    dev-01, test-01, prod-01 uses lowercase and hyphens with numbers, fitting best practices. dev, test_env, production uses underscore, B is long but valid, D uses uppercase.
  3. Step 3: Choose best consistent and clear naming

    dev-01, test-01, prod-01 is concise, consistent, and follows all rules.
  4. Final Answer:

    dev-01, test-01, prod-01 -> Option C
  5. Quick Check:

    Lowercase + hyphens + numbers = best practice [OK]
Hint: Use lowercase, hyphens, and numbers for clarity [OK]
Common Mistakes:
  • Using uppercase letters
  • Using underscores
  • Choosing inconsistent naming styles