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

Exam Terraform Associate All Questions

View all questions & answers for the Terraform Associate exam

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, 7 months 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 13 times
Oleg_gol
1 year, 6 months 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
...
...
ArnaldoW
Highly Voted 1 year, 7 months 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 5 times
...
Kriegs
Most Recent 2 months, 3 weeks ago
The question seems to be poorly worded, but as I understand vote for B, if you define output in a child module you can refer to it in a root configuration with no need to provide additional outputs.
upvoted 1 times
...
090200f
3 months, 3 weeks ago
Selected Answer: C
https://developer.hashicorp.com/terraform/language/values/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. Child modules can't reference each others outputs. You have to explicitly pass them in the root module from one module to the second, e.g. in root: module "ServicePrincipal" { } module "aks" { client_id = module.ServicePrincipal.client_id } https://stackoverflow.com/questions/73809505/how-to-use-output-of-one-child-module-as-an-input-to-another-child-module-in-ter because of this seems like ans is C. Declare the output in both the root and child module
upvoted 1 times
...
anubha.agrahari
7 months, 3 weeks 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
11 months, 3 weeks ago
Selected Answer: B
you don't need to declare output variable in root it work with child fine
upvoted 2 times
...
Simplon
1 year, 1 month 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 3 times
...
enc_0343
1 year, 1 month 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
1 year, 1 month ago
B is the correct answer in my opinion
upvoted 1 times
...
Oleg_gol
1 year, 6 months ago
Selected Answer: B
b - https://developer.hashicorp.com/terraform/language/values/outputs
upvoted 1 times
Misiek
1 year, 2 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, 7 months 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, 7 months ago
Answer B
upvoted 1 times
...
Nunyabiznes
1 year, 7 months 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, 7 months 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, 7 months 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 3 times
...
lordoftheringsnewavatar
1 year, 7 months 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 ...