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.
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
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.
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.
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
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.
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.
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
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.
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.
tbhtp
Highly Voted 1 year, 7 months agoOleg_gol
1 year, 6 months agoArnaldoW
Highly Voted 1 year, 7 months agoKriegs
Most Recent 2 months, 3 weeks ago090200f
3 months, 3 weeks agoanubha.agrahari
7 months, 3 weeks agokareem_ashraf
11 months, 3 weeks agoSimplon
1 year, 1 month agoenc_0343
1 year, 1 month agoPikopo
1 year, 1 month agoOleg_gol
1 year, 6 months agoMisiek
1 year, 2 months agooskarq
1 year, 7 months agoAlenKumar
1 year, 7 months agoNunyabiznes
1 year, 7 months agoNunyabiznes
1 year, 7 months agocamps
1 year, 7 months agolordoftheringsnewavatar
1 year, 7 months ago