Bird
Raised Fist0
Terraformcloud~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of output values in a Terraform configuration?
easy
A. To create new cloud resources
B. To display important information after Terraform applies changes
C. To define variables used inside Terraform modules
D. To store Terraform state files remotely

Solution

  1. Step 1: Understand the role of output values

    Output values are used to show key information after Terraform finishes applying infrastructure changes.
  2. Step 2: Differentiate outputs from other Terraform features

    Variables define inputs, resources create infrastructure, and state files store deployment state. Outputs specifically display results.
  3. Final Answer:

    To display important information after Terraform applies changes -> Option B
  4. Quick Check:

    Outputs = display info after apply [OK]
Hint: Outputs show info after apply, not inputs or resources [OK]
Common Mistakes:
  • Confusing outputs with variables
  • Thinking outputs create resources
  • Mixing outputs with state storage
2. Which of the following is the correct syntax to define an output named instance_ip in Terraform?
easy
A. output "instance_ip" { value = aws_instance.example.private_ip }
B. output instance_ip = aws_instance.example.private_ip
C. output "instance_ip" = aws_instance.example.private_ip
D. output { instance_ip = aws_instance.example.private_ip }

Solution

  1. Step 1: Recall Terraform output block syntax

    Outputs use the block syntax: output "name" { value = ... }.
  2. Step 2: Match syntax to options

    output "instance_ip" { value = aws_instance.example.private_ip } matches the correct block syntax with quotes and value assignment.
  3. Final Answer:

    output "instance_ip" { value = aws_instance.example.private_ip } -> Option A
  4. Quick Check:

    Output block = output "name" { value = ... } [OK]
Hint: Outputs need block syntax with quotes and value key [OK]
Common Mistakes:
  • Missing quotes around output name
  • Using equals sign outside block
  • Incorrect block structure
3. Given this Terraform output block:
output "bucket_name" {
  value = aws_s3_bucket.my_bucket.id
}

What will Terraform display after terraform apply if the bucket ID is my-bucket-123?
medium
A. "aws_s3_bucket.my_bucket.id"
B. "my-bucket-123"
C. bucket_name = "my-bucket-123"
D. No output will be shown

Solution

  1. Step 1: Understand output display format

    Terraform outputs show the output name followed by an equals sign and the value.
  2. Step 2: Apply the known value

    The value aws_s3_bucket.my_bucket.id is "my-bucket-123", so output shows: bucket_name = "my-bucket-123".
  3. Final Answer:

    bucket_name = "my-bucket-123" -> Option C
  4. Quick Check:

    Output format = name = value [OK]
Hint: Outputs show name = value after apply [OK]
Common Mistakes:
  • Expecting only the value without name
  • Confusing resource attribute with output text
  • Thinking outputs are hidden by default
4. You wrote this output block:
output "db_password" {
  value = var.db_password
  sensitive = true
}

After terraform apply, you still see the password printed in the console. What is the likely cause?
medium
A. You ran terraform output -raw db_password after apply
B. You must set sensitive = false to hide output
C. Terraform does not support sensitive outputs
D. The output block syntax is invalid

Solution

  1. Step 1: Understand sensitive output behavior

    Sensitive outputs hide values in the terraform apply console and standard terraform output. However, terraform output -raw <name> bypasses this and shows the value.
  2. Step 2: Identify cause of exposure

    The likely cause is running terraform output -raw db_password, which reveals sensitive values.
  3. Final Answer:

    You ran terraform output -raw db_password after apply -> Option A
  4. Quick Check:

    Sensitive hides output unless -raw [OK]
Hint: Sensitive hides output unless -raw used [OK]
Common Mistakes:
  • Thinking sensitive = false hides output
  • Believing Terraform can't mark outputs sensitive
  • Assuming syntax error causes exposure
5. You want to output a list of instance IPs from multiple AWS instances created with a count. Which output block correctly returns all private IPs after apply?
resource "aws_instance" "web" {
  count = 3
  private_ip = "10.0.0.${count.index + 1}"
}

output "instance_ips" {
  value = ???
}
hard
A. aws_instance.web[0].private_ip
B. aws_instance.web.*
C. aws_instance.web.private_ip
D. [for i in aws_instance.web : i.private_ip]

Solution

  1. Step 1: Understand how to access multiple instances' attributes

    When using count, aws_instance.web is a list of resources. To get all private_ip values, use a for expression to extract each.
  2. Step 2: Evaluate options for correct syntax

    [for i in aws_instance.web : i.private_ip] uses a for expression to collect private_ip from each instance, which is valid and recommended.
  3. Final Answer:

    [for i in aws_instance.web : i.private_ip] -> Option D
  4. Quick Check:

    Use for expression to list attributes from count resources [OK]
Hint: Use for expressions to output lists from multiple resources [OK]
Common Mistakes:
  • Using wildcard (*) syntax without the attribute
  • Accessing single instance only
  • Trying to output resource without indexing