Challenge - 5 Problems
Terraform Arguments & Expressions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Configuration
intermediate2:00remaining
Terraform Expression Output Result
What is the value of the
count local value after this Terraform expression is evaluated?Terraform
variable "environment" { default = "prod" } variable "instance_count" { default = 3 } locals { count = var.environment == "prod" ? var.instance_count * 2 : var.instance_count }
Attempts:
2 left
💡 Hint
Check the condition in the ternary expression and how it affects the count.
✗ Incorrect
Since the environment is 'prod', the condition is true, so the count is instance_count * 2 = 3 * 2 = 6.
❓ service_behavior
intermediate2:00remaining
Terraform Conditional Argument Behavior
Given this Terraform resource snippet, what will be the value of the
enable_monitoring argument when var.enable is false?Terraform
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" enable_monitoring = var.enable ? true : false }
Attempts:
2 left
💡 Hint
Look at the ternary expression and the value of var.enable.
✗ Incorrect
Since var.enable is false, the ternary expression evaluates to false, so enable_monitoring is set to false.
❓ Architecture
advanced2:30remaining
Terraform Expression for Dynamic Subnet Selection
Which option correctly uses a Terraform expression to select all subnet IDs from
var.subnets where the availability_zone equals var.az?Terraform
variable "subnets" { type = list(object({ id = string availability_zone = string })) } variable "az" { type = string } locals { selected_subnets = <EXPRESSION> }
Attempts:
2 left
💡 Hint
Terraform uses 'for' expressions with 'if' filters after the colon.
✗ Incorrect
Option A correctly uses the syntax: [for item in list : expression if condition]. Other options have syntax errors.
❓ security
advanced2:00remaining
Terraform Sensitive Variable Expression
What will happen if you try to output a sensitive variable directly in Terraform like this?
Terraform
variable "db_password" { type = string sensitive = true } output "password" { value = var.db_password }
Attempts:
2 left
💡 Hint
Sensitive variables are handled specially in outputs.
✗ Incorrect
Terraform masks sensitive output values by showing instead of the actual value.
✅ Best Practice
expert3:00remaining
Terraform Expression for Optional Argument with Default
Which option correctly sets an optional argument
tags in a resource to use var.tags if defined, or an empty map if not defined?Terraform
variable "tags" { type = map(string) default = null } resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" tags = <EXPRESSION> }
Attempts:
2 left
💡 Hint
Terraform uses the null-coalescing operator for default values.
✗ Incorrect
Option A uses the null-coalescing operator '??' which returns var.tags if not null, else {}.