Answer C
The question asks how to output the value in the cli, if we declare output only in a child module it will not be shown in the cli, we need one more output in the root configuration
n 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
B. Declare the output in the child module.
To output returned values from a child module in the Terraform CLI output, you need to declare the output in the child module.
Option A, declaring the output in the root configuration, is incorrect because the output is defined in the child module. Option C, declaring the output in both the root and child module, is also incorrect because this would create duplicate outputs. Option D, none of the above, is incorrect because there is a way to output returned values from a child module in the Terraform CLI output.
A child module can use outputs to expose a subset of its resource attributes to a parent module. A root module can use outputs to print certain values in the CLI output after running terraform apply .
1. To pass a value from child module to parent module, it must declare the output variable in child module.
2. To print out a value, it must declare the output variable in parent module.
to output returned values from a child module to CLI - Declare the output in both the root and child module. For example:
child-module.tf
output "child_foo" {
value = "foobar"
}
main.tf
module "child" {
source = "path/to/child"
}
output "output_to_cli" {
value = module.child.child_foo
}
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.
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.
nicecurls
Highly Voted 1 year, 4 months agoshanx910
1 year, 1 month agobella
Most Recent 7 months agoNewuser95
10 months, 2 weeks agoalen995454
11 months, 3 weeks agokareem_ashraf
1 year, 1 month agoTronko86
1 year, 2 months ago3cc17f1
1 year, 2 months agoTire
1 year, 2 months agoenc_0343
1 year, 3 months agoBaburTurk
1 year, 4 months agoMisiek
1 year, 4 months agoRonZhong
1 year, 4 months agoakm_1010
1 year, 4 months agowota
2 months, 4 weeks agoRajmane
1 year, 4 months agoShakDaddy
1 year, 5 months ago