0
0
Terraformcloud~10 mins

Why workspaces separate environments in Terraform - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the current workspace in Terraform.

Terraform
terraform.workspace == "[1]"
Drag options to blanks, or click blank then click option'
Adev
Bmain
Cprod
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' or 'prod' instead of 'default' as the workspace name.
2fill in blank
medium

Complete the code to create a resource only in the 'prod' workspace.

Terraform
count = terraform.workspace == "[1]" ? 1 : 0
Drag options to blanks, or click blank then click option'
Aprod
Bdev
Ctest
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dev' or 'default' instead of 'prod' for production workspace.
3fill in blank
hard

Fix the error in the condition to check if the workspace is 'dev'.

Terraform
if terraform.workspace = [1] { count = 1 } else { count = 0 }
Drag options to blanks, or click blank then click option'
A'dev'
B== "dev"
C"dev" == terraform.workspace
D"dev"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
Not quoting the workspace name string.
4fill in blank
hard

Fill both blanks to create a map of environment names to workspace names.

Terraform
environments = { "production": "[1]", "development": "[2]" }
Drag options to blanks, or click blank then click option'
Aprod
Bdev
Cdefault
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up workspace names for production and development.
5fill in blank
hard

Fill all three blanks to conditionally set a variable based on the workspace.

Terraform
variable "db_name" {
  default = terraform.workspace == "[1]" ? "prod_db" : terraform.workspace == "[2]" ? "dev_db" : "[3]"
}
Drag options to blanks, or click blank then click option'
Aprod
Bdev
Ctest_db
Ddefault_db
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect workspace names or default values.