0
0
Terraformcloud~10 mins

Terraform.workspace interpolation - Interactive Code Practice

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

Complete the code to reference the current Terraform workspace.

Terraform
output "current_workspace" {
  value = terraform.[1]
}
Drag options to blanks, or click blank then click option'
Aconfig
Bstate
Cworkspace
Dmodule
Attempts:
3 left
💡 Hint
Common Mistakes
Using terraform.state instead of terraform.workspace
Trying terraform.module which is unrelated
Using terraform.config which does not exist
2fill in blank
medium

Complete the code to conditionally set a variable based on the current workspace.

Terraform
variable "env" {
  default = terraform.[1] == "prod" ? "production" : "development"
}
Drag options to blanks, or click blank then click option'
Amodule
Bworkspace
Cconfig
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using terraform.state which is not the workspace
Trying terraform.module which is unrelated
Using terraform.config which does not exist
3fill in blank
hard

Fix the error in the code to correctly output the workspace name.

Terraform
output "workspace_name" {
  value = terraform.[1]
}
Drag options to blanks, or click blank then click option'
Aworkspace()
Bworkspace_name()
Cworkspace_name
Dworkspace
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses to terraform.workspace making it a function call
Using incorrect property names like workspace_name
4fill in blank
hard

Fill both blanks to create a resource name that includes the current workspace.

Terraform
resource "aws_s3_bucket" "example" {
  bucket = "my-app-$[1]-$[2]"
  acl    = "private"
}
Drag options to blanks, or click blank then click option'
Aterraform.workspace
Bvar.env
Cterraform.state
Dlocal.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using terraform.state which is not the workspace
Using local.name which is unrelated
Mixing up the order of workspace and env
5fill in blank
hard

Fill all three blanks to create a tag map including the workspace and environment.

Terraform
tags = {
  Name        = "app-$[1]"
  Environment = "$[2]"
  Workspace   = terraform.[3]
}
Drag options to blanks, or click blank then click option'
Avar.env
Bproduction
Cworkspace
Dlocal.env
Attempts:
3 left
💡 Hint
Common Mistakes
Using local.env instead of var.env
Using terraform.state instead of terraform.workspace
Putting quotes around terraform.workspace