0
0
Terraformcloud~20 mins

Output values after apply in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2: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
}
A"The public IP address of the instance, e.g., 54.123.45.67"
B"The AMI ID used, e.g., ami-12345678"
C"The instance type, e.g., t2.micro"
D"An empty string because public_ip is not set"
Attempts:
2 left
💡 Hint
The output references the public_ip attribute of the aws_instance resource.
Configuration
intermediate
2: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"]
}
A"eu_west_1"
B"EU (Ireland)"
C"US East (N. Virginia)"
D"null"
Attempts:
2 left
💡 Hint
The output accesses the map variable with key "eu_west_1".
Architecture
advanced
2: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
}
A["subnet-abc123", "subnet-def456", "subnet-ghi789"]
B["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24"]
C"subnet-abc123"
Dnull
Attempts:
2 left
💡 Hint
The output uses the splat operator to collect all subnet IDs.
security
advanced
2: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
}
AThe password will be shown in the output after apply.
BThe password will be printed in plain text in the Terraform state file only.
CThe password will be hidden in the output and not shown in the CLI.
DTerraform will raise an error because sensitive outputs are not allowed.
Attempts:
2 left
💡 Hint
Sensitive outputs are designed to hide values in CLI output.
Best Practice
expert
2: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
}
A"" (empty string)
Bnull
CThe ARN string of the bucket, e.g., arn:aws:s3:::my-example-bucket
DA runtime error because the resource does not exist
Attempts:
2 left
💡 Hint
Accessing an index of a resource with count=0 causes an error.