Challenge - 5 Problems
Terraform Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Output value of a computed resource attribute
Given the Terraform configuration below, what will be the output value of
instance_ip after applying?Terraform
resource "aws_instance" "example" { ami = "ami-12345678" instance_type = "t2.micro" tags = { Name = "example-instance" } } output "instance_ip" { value = aws_instance.example.public_ip }
Attempts:
2 left
💡 Hint
The output references the public_ip attribute of the aws_instance resource.
✗ Incorrect
The output value references aws_instance.example.public_ip, which is the public IP address assigned to the instance after creation.
❓ Configuration
intermediate2:00remaining
Output value from a map variable
What will be the output of
region_name after applying this Terraform configuration?Terraform
variable "regions" { type = map(string) default = { us_east_1 = "US East (N. Virginia)" eu_west_1 = "EU (Ireland)" } } output "region_name" { value = var.regions["eu_west_1"] }
Attempts:
2 left
💡 Hint
The output accesses the map variable with key "eu_west_1".
✗ Incorrect
The output value is the string mapped to the key "eu_west_1" in the variable regions, which is "EU (Ireland)".
❓ Architecture
advanced2:00remaining
Output value of a list of resource IDs
After applying the following Terraform code, what will be the output value of
subnet_ids?Terraform
resource "aws_subnet" "example" { count = 3 vpc_id = "vpc-123456" cidr_block = "10.0.${count.index}.0/24" } output "subnet_ids" { value = aws_subnet.example[*].id }
Attempts:
2 left
💡 Hint
The output uses the splat operator to collect all subnet IDs.
✗ Incorrect
The output collects the id attribute from all three aws_subnet resources into a list of subnet IDs.
❓ security
advanced2:00remaining
Outputting sensitive values
Consider this Terraform output configuration. What will happen after apply?
Terraform
variable "db_password" { type = string sensitive = true } output "database_password" { value = var.db_password sensitive = true }
Attempts:
2 left
💡 Hint
Sensitive outputs are designed to hide values in CLI output.
✗ Incorrect
Marking an output as sensitive hides its value from CLI output but still stores it encrypted in the state file.
✅ Best Practice
expert2:00remaining
Output value referencing a resource attribute that may not exist
What will be the output value of
bucket_arn after applying this Terraform configuration if the resource aws_s3_bucket.example is conditionally created with count = 0?Terraform
resource "aws_s3_bucket" "example" { count = 0 bucket = "my-example-bucket" } output "bucket_arn" { value = aws_s3_bucket.example[0].arn }
Attempts:
2 left
💡 Hint
Accessing an index of a resource with count=0 causes an error.
✗ Incorrect
Since the resource count is zero, the list aws_s3_bucket.example is empty. Accessing index 0 causes a runtime error.