You have declared an input variable called environment in your parent module. What must you do to pass the value to a child module in the configuration?
You have declared an input variable called environment in your parent module. What must you do to pass the value to a child module in the configuration?
To pass a value from a parent module to a child module in Terraform, you need to declare an input variable in the child module that corresponds to the variable declared in the parent module. This ensures that the value from the parent module can be received and used by the child module. Simply declaring the variable in the parent module or assuming an inheritance will not work. The child module must explicitly define the necessary input variable to accept values.
C is correct as the question is about passing a variable. So if you want the parent to pass its output to its child you need to configure an input variable for that. The name of the input variable makes no sense but maybe that is to emphasize on the fact that the name of the input variable is arbitrary. "That module may call other modules and connect them together by passing output values from one to input values of another." https://www.terraform.io/language/modules/develop
All given options are wrong, they don't make any sense You have declared a variable called "environment" A. where did you get the var.node_count, is it related to the question? B. You can do that, but it is not what you need for the question C. Then what? node_count variable should accept number, not a string. Assuming "environment" variable will hold string value like Dev, UAT, Prod D. Child module will not automatically inherit variables from parent module They don't make any sense
module "child_module" { source = "./child_module" environment = var.environment }
Mr. Nunyabusines, may you like to rewrite the answer as: module "child_module" { source = "./parent_module" environment = var.environment }
C. Declare a node_count input variable for child module. When you declare an input variable in a parent module, the child module will not automatically inherit the value of the variable. You must explicitly declare the variable in the child module.
C. Declare a node_count input variable for child module. When passing variables from a parent module to a child module in Terraform, you need to explicitly declare the variables in both the parent and the child modules. In this case, you would need to declare an input variable for the child module that corresponds to the input variable declared in the parent module. So, the correct option is C. Option A is incorrect because it is using an example variable that is not related to the input variable mentioned in the question. Option B is incorrect because it refers to how to set the value of the variable, but not how to pass the value from the parent to the child module. Option D is also incorrect because child modules do not automatically inherit the variables of their parent modules.
C, declaration of variables is not done in terraform.tfvars.
C - correct for every variable used in terraform module (root/child) you must first declare it. Without declaration in child module the variable will not be recognized.
# Parent module module "child" { source = "./child" node_count = var.environment } # Child module variable "node_count" { type = number }
Declare the variable in a terraform.tfvars file --> doesnot apply to child module -->https://www.terraform.io/language/values/variables
Searched in google " terraform node_count" no result. What is this node_count do?
The answer is B. TFVARS is like a global variable.
B is not correct. Reading something from the same place is not passing a variable. Imagine what happens if the parent gets its value passed with -var.
module "child_module" { source = "./path_to_child_module" environment = var.environment } Therefore, the correct answer is: A. Add node_count = var.node_count
You need to pass the value. (The child module should have the variable, that the child module developer's work)
I vote for C
C. Declare a node_count input variable for the child module. In Terraform, input variables are used to parameterize Terraform configurations. When using child modules, it is necessary to pass values for the input variables defined in the child module. The values for the input variables can be passed using different methods such as using default values, command-line flags, environment variables, variable files, and so on.
https://www.terraform.io/language/modules/develop C is a correct answer
A is the correct answer.