Complete the code to select the current workspace in Terraform.
terraform.workspace == "[1]"
The default workspace is named "default" in Terraform. This code checks if the current workspace is the default one.
Complete the code to create a resource only in the 'prod' workspace.
count = terraform.workspace == "[1]" ? 1 : 0
This code sets the resource count to 1 only if the current workspace is 'prod', otherwise 0, so the resource is created only in 'prod'.
Fix the error in the condition to check if the workspace is 'dev'.
if terraform.workspace = [1] { count = 1 } else { count = 0 }
The single equals sign '=' is an assignment, not a comparison. The correct comparison uses '==' and the value should be a string in quotes.
Fill both blanks to create a map of environment names to workspace names.
environments = { "production": "[1]", "development": "[2]" }This map links the environment names to their corresponding workspace names: 'production' to 'prod' and 'development' to 'dev'.
Fill all three blanks to conditionally set a variable based on the workspace.
variable "db_name" { default = terraform.workspace == "[1]" ? "prod_db" : terraform.workspace == "[2]" ? "dev_db" : "[3]" }
This sets the database name to 'prod_db' if in 'prod' workspace, 'dev_db' if in 'dev' workspace, and 'default_db' otherwise.