Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Terraform Associate topic 1 question 232 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 232
Topic #: 1
[All Terraform Associate Questions]

How would you output returned values from a child module?

  • A. Declare the output in the root configuration
  • B. Declare the output in the child module
  • C. Declare the output in both the root and child module
  • D. None of the above
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
tbhtp
Highly Voted 1 year, 1 month ago
Selected Answer: C
C. Declare the output in both the root and child module To output returned values from a child module, you need to declare the output in both the child and root module. In the child module, you need to declare an output block, which defines the values that the child module will return. In the root module, you will reference the output values from the child module using the syntax module.<module_name>.<output_name>. You can then declare an output block in the root module to display the values or use them elsewhere in the root module configuration.
upvoted 11 times
Oleg_gol
1 year ago
chatGPT? ) In a parent module, outputs of child modules are available in expressions as module.<MODULE NAME>.<OUTPUT NAME>. For example, if a child module named web_server declared an output named instance_ip_addr, you could access that value as module.web_server.instance_ip_addr. https://developer.hashicorp.com/terraform/language/values/outputs
upvoted 3 times
...
...
anubha.agrahari
Most Recent 1 month ago
B In a parent module, outputs of child modules are available in expressions as module.<MODULE NAME>.<OUTPUT NAME>. For example, if a child module named web_server declared an output named instance_ip_addr, you could access that value as module.web_server.instance_ip_addr.
upvoted 2 times
...
kareem_ashraf
5 months ago
Selected Answer: B
you don't need to declare output variable in root it work with child fine
upvoted 1 times
...
Simplon
6 months, 3 weeks ago
Selected Answer: C
Just tested it. If I don't declare an output block in my root module reffering to my child module's output , I get no returned output on the CLI.
upvoted 2 times
...
enc_0343
7 months ago
Selected Answer: C
You can use outputs.tf in the child module and the output block in the root module.
upvoted 1 times
...
Pikopo
7 months, 1 week ago
B is the correct answer in my opinion
upvoted 1 times
...
Oleg_gol
1 year ago
Selected Answer: B
b - https://developer.hashicorp.com/terraform/language/values/outputs
upvoted 1 times
Misiek
8 months ago
Accessing Child Module Outputs In a parent module, outputs of child modules are available in expressions as module.<MODULE NAME>.<OUTPUT NAME>. For example, if a child module named web_server declared an output named instance_ip_addr, you could access that value as module.web_server.instance_ip_addr.
upvoted 1 times
...
...
oskarq
1 year ago
Selected Answer: B
How would you output returned values from a child module? A. Declare the output in the root configuration B. Declare the output in the child module C. Declare the output in both the root and child module D. None of the above
upvoted 1 times
...
AlenKumar
1 year ago
Answer B
upvoted 1 times
...
ArnaldoW
1 year, 1 month ago
Selected Answer: B
In Terraform, it is not necessary to declare an output in both the root and child module. The output declared in the child module will be available to the root module, so you only need to declare an output in the root module if you want to expose that value to the outside world or use it in another module. If you declare an output in both the root and child module with the same name, Terraform will use the output from the root module as the final output. This can be useful if you want to override the output value of the child module with a different value in the root module. However, it is generally a good practice to avoid duplicate output names between modules to prevent confusion and ensure that the output values are clearly defined and organized. In summary, it is not necessary to declare an output in both the root and child module, but if you do, the output from the root module will override the output from the child module. It is recommended to use unique output names to avoid confusion and ensure clear organization of output values.
upvoted 4 times
...
Nunyabiznes
1 year, 1 month ago
Selected Answer: B
child module: output "example_output" { value = "some value" } PARENT Module: module "example_module" { source = "./example_module" } output "example_output_from_child" { value = module.example_module.example_output }
upvoted 2 times
Nunyabiznes
1 year, 1 month ago
The clue here is "returned value" from child module. So the value is already declared in child module, so you just need to call it in Parent
upvoted 4 times
...
...
camps
1 year, 1 month ago
Selected Answer: B
B. Declare the output in the child module When you want to output returned values from a child module, you should declare the output in the child module itself. Outputs in Terraform (or other Infrastructure as Code tools) are used to expose certain values or results from one module, which can then be consumed by other modules or scripts.
upvoted 2 times
...
lordoftheringsnewavatar
1 year, 1 month ago
B for me.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...