0
0
Terraformcloud~10 mins

String interpolation in Terraform - Interactive Code Practice

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

Complete the code to interpolate the variable 'name' inside the string.

Terraform
output "greeting" {
  value = "Hello, ${var.[1]!"
}
Drag options to blanks, or click blank then click option'
Ausername
Buser
Cname
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist like 'username' or 'user'.
Forgetting to use the 'var.' prefix inside interpolation.
2fill in blank
medium

Complete the code to concatenate the variable 'region' with a string using interpolation.

Terraform
resource "aws_instance" "example" {
  tags = {
    Name = "web-server-[1]"
  }
}
Drag options to blanks, or click blank then click option'
A${var.region}
Bvar.region
C${region}
Dregion
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the interpolation syntax and writing just 'var.region'.
Using the variable name without the 'var.' prefix.
3fill in blank
hard

Fix the error in the interpolation syntax to correctly reference the 'environment' variable.

Terraform
output "env_name" {
  value = "Current environment is ${var.[1]"
}
Drag options to blanks, or click blank then click option'
Aenvironment}
Benvironment
Cenvironment}}
D{environment}
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the closing brace '}' in the interpolation.
Adding extra braces or missing the variable prefix.
4fill in blank
hard

Fill both blanks to create a tag that combines 'app' and 'version' variables with a dash.

Terraform
resource "aws_s3_bucket" "bucket" {
  tags = {
    Name = "${var.[1]-${var.[2]"
  }
}
Drag options to blanks, or click blank then click option'
Aapp
Bversion
Cenv
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using variables that do not exist like 'env' or 'name'.
Forgetting to use the 'var.' prefix.
5fill in blank
hard

Fill all three blanks to create an output that shows the full resource ID with region and environment.

Terraform
output "resource_id" {
  value = "arn:aws:ec2:${var.[1]:${var.[2]:instance/${var.[3]"
}
Drag options to blanks, or click blank then click option'
Aregion
Baccount_id
Cinstance_id
Denvironment
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variable names or missing the 'var.' prefix.
Using 'environment' instead of 'account_id' or 'instance_id'.