In the question
Which of the following statements are true regarding output variables?
Below option is given as incorrect.
Running the “terraform plan” will render the output variables defined
But i could see the output variables and their values showing in plan as well.
Ex:-
define any output variable like below
output "course" {
value = "terraform"
}
run terraform plan
, you will see the output variable and it’s value showing in plan output as well
Lab link : MCQ - Variables - KodeKloud
If you make the output a literal string like "terraform"
then its value is known at plan time - however I cannot see any use case where you would define an output like that.
If the output is the attribute of a resource that needs to be created or modified, plan will say (known after apply)
therefore you do not see the actual value, because it is not known at plan time.
My question wasn’t about use case rather about the wording of option.
I could think of one use-case where i want to output the variable value of calling module
I may want to output a variable value.
output "course" {
value = var.course
}
You may indeed, although because you input the variable, you already know what it is, so why output it again?
The main use of outputs is to find something that is not known until the configuration is applied, such as the ID of an EC2 instance you have created.
If you had a module that created some infra and passed its ID as an argument to another module, but you wanted to see the ID at the end, then it should be the responsibility of the code that created the infra to output its ID.
We can continue to split hairs on this, but the bottom line is that plan will not display outputs if they are related to resources that do not yet exist. Only known values, which you must have personally supplied somehow either as vars or constants would be output.
To reword the question would probably give away too much of the answer
Running the “terraform plan” may render some the output variables defined
To me, the original wording implies ALL outputs, which except in the unusual cases you have raised, is false
Thanks for the explanation.