0
0
Terraformcloud~20 mins

String interpolation in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform String Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform String Interpolation Syntax
What will be the output of the following Terraform expression?

"Hello, ${var.name}! Welcome to ${var.region}."

Assume var.name = "Alice" and var.region = "us-west-2".
A"Hello, Alice! Welcome to us-west-2."
B"Hello, ${var.name}! Welcome to ${var.region}."
C"Hello, Alice! Welcome to ${var.region}."
D"Hello, var.name! Welcome to var.region."
Attempts:
2 left
💡 Hint
Terraform replaces variables inside ${} with their values.
Configuration
intermediate
2:00remaining
Correct Use of String Interpolation in Resource Names
Which option correctly uses string interpolation to create an AWS S3 bucket name with a prefix and environment variable?

Assume var.env = "prod" and var.prefix = "myapp".
Abucket = "${var.prefix-var.env}-bucket"
Bbucket = "${var.prefix}-${var.env}-bucket"
Cbucket = "var.prefix-var.env-bucket"
D"tekcub-}vne.rav{$-}xiferp.rav{$" = tekcub
Attempts:
2 left
💡 Hint
Use ${} around each variable and separate with hyphens outside the braces.
Architecture
advanced
2:00remaining
Combining String Interpolation with Conditional Expressions
Given the Terraform variable var.is_production which is a boolean, which option correctly sets the resource tag Environment to "prod" if true, or "dev" if false, using string interpolation?
Atags = { Environment = "${var.is_production ? "prod" : dev}" }
Btags = { Environment = "${if var.is_production then "prod" else "dev"}" }
Ctags = { Environment = "${var.is_production ? prod : dev}" }
Dtags = { Environment = "${var.is_production ? "prod" : "dev"}" }
Attempts:
2 left
💡 Hint
Terraform uses the ternary operator inside ${} with quotes around string results.
security
advanced
2:00remaining
Avoiding Sensitive Data Exposure in String Interpolation
Which option correctly avoids exposing a sensitive variable var.db_password in Terraform output using string interpolation?
Aoutput "db_password" { value = var.db_password }
Boutput "db_password" { value = var.db_password, sensitive = true }
Coutput "db_password" { value = "${var.db_password}" sensitive = true }
Doutput "db_password" { value = "${var.db_password}" }
Attempts:
2 left
💡 Hint
Use the sensitive attribute to hide output values.
service_behavior
expert
2:00remaining
Effect of Incorrect String Interpolation on AWS Resource Creation
What will happen if you define an AWS EC2 instance resource with the following name attribute?

name = "${var.instance_name"

Assuming var.instance_name = "webserver".
ATerraform plan will fail with a syntax error due to missing closing brace.
BTerraform will create the instance with name literally '${var.instance_name'.
CTerraform will create the instance with name 'webserver'.
DTerraform plan will succeed but instance name will be empty.
Attempts:
2 left
💡 Hint
Check for matching braces in interpolation expressions.