TF-004 Read, generate and modify configuration Practice Question
Exhibit
output "instance_ip" {
value = aws_instance.web.public_ip
}Refer to the exhibit. What is the purpose of this output block?
⚠ Common exam trap
The TF-003 exam often tests the distinction between Terraform outputs and other mechanisms like variables or resource declarations, and the trap here is that candidates confuse the display-only purpose of outputs with the ability to store data in files or create external resources, leading them to select options A, B, or C.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
To display the public IP address of the instance after apply.
The output block shown in the exhibit is a Terraform output value, which is defined using the `output` block in a configuration file. Its purpose is to display the public IP address of the instance in the terminal after `terraform apply` completes, providing a quick reference for the user. Option D correctly identifies this behavior, as outputs are designed to surface resource attributes to the user without storing them or creating external records.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
To store the public IP in a local file.
Why it's wrong here
Terraform `output` blocks are designed to display values to the console or make them accessible to other configurations via remote state. They do not inherently write data to local files as a default behavior. To store an output value in a local file, a separate mechanism like a `local_file` resource or a post-provisioning script would be required, explicitly referencing the output value. The `output` block itself only defines what value is exposed, not how it's persisted to the local filesystem.
- ✗
To set the public IP as a variable for use in other configurations.
Why it's wrong here
Terraform `output` blocks expose values from the current configuration, typically after resources have been created, for display or remote state access. They do not define or set input variables for other configurations. Input variables are declared using `variable` blocks and are used to parameterize a configuration *before* it's applied. While an output from one configuration can be used as an input variable in another via remote state data sources, the output block itself doesn't "set" a variable.
- ✗
To create a DNS record with the public IP.
Why it's wrong here
Terraform `output` blocks are purely for exposing values from the state or resources, making them visible or accessible. They are declarative statements that define what information should be displayed or made available, not actions to create infrastructure. Creating infrastructure components like DNS records requires a dedicated Terraform `resource` block (e.g., `aws_route53_record`, `google_dns_record`) that interacts with the respective cloud provider's API. An output block merely references an attribute of an existing or newly created resource.
- ✓
To display the public IP address of the instance after apply.
Why this is correct
The primary purpose of a Terraform `output` block is to define values that will be displayed to the user's console upon successful completion of a `terraform apply` operation. This allows operators to easily retrieve important information, such as an instance's public IP address, connection strings, or URLs, without needing to inspect the state file directly. Additionally, these outputs are stored in the state file and can be programmatically accessed by other Terraform configurations via remote state data sources.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.