Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 101


If a module declares a variable with a default, that variable must also be defined within the module.

Show Answer
Correct Answer: B

If a module declares a variable with a default value, it does not necessarily need to be defined within the module. The default value will be used if the variable is not assigned a value by the module using it. This allows the module to function with its default settings unless a different value is explicitly provided.

Discussion

12 comments
Sign in to comment
govsOption: B
Apr 9, 2024

If a module declares a variable with a default value, it is not necessary to define the variable within the module calling the module. The module will automatically use the default value if a value is not explicitly assigned to the variable in the calling module

EltoothOption: B
Jun 29, 2023

B is correct answer.

NunyabiznesOption: B
Mar 24, 2024

False. If a module declares a variable with a default value, it does not necessarily need to be defined within the module. The default value will be used if the variable is not set in the calling module. For example, consider the following module: ``` variable "instance_type" { description = "The instance type to use" default = "t2.micro" } resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = var.instance_type } ```

Nunyabiznes
Mar 24, 2024

In this module, a variable called instance_type is declared with a default value of t2.micro. The default value will be used if the variable is not set in the calling module. If the calling module does not set the instance_type variable, the default value of t2.micro will be used. If the calling module does set the instance_type variable, the value from the calling module will be used instead of the default. It is important to note that if a variable is declared without a default value and is not set in the calling module, Terraform will prompt the user to enter a value for that variable.

Clapton79
Nov 10, 2024

This question does not make sense in its current form. (Very poor English, sorry) You declare the variable with variable "my_var" {type=string} and in there you may add a default: variable "my_var" { type=string default="a" } SETTING a variable in a statement calling a module that contains this variable is not compulsory. module "my_module" { source= "./this_module" my_var = "b" # <-- you can omit this in which case the value will be "a" }

umavaja
Dec 10, 2024

Agree, very poor English, same issue even for UDEMY courses as well Terraform documentation

AnonymousOption: B
Jun 3, 2023

when no value is passed, default value will be automatically be taken.

bukake
Aug 19, 2023

Where are 102-103-104 Questions?

kopper2019
Aug 24, 2023

no idea, I am taking exam tomorrow

hello2022
Sep 14, 2023

How did you do? How relevant were these questions.

hello2022
Sep 14, 2023

How did you do? How relevant were these questions.

traceme
May 10, 2023

Why not A . When we define the variable as default , we need to pass tha value for the variables right

habros
Jun 5, 2023

It already had a variable. Worse case it knows where to get if it’s not manually defined

SilentMilliOption: B
Mar 13, 2024

A module can declare a variable with a default value without defining it within the module. This is because the variable can be used as-is with the default value, or it can be assigned a new value by code that imports the module.

Maaran07
May 20, 2023

It is not mandatory to define inside module. default can be in module itself.

Power123
Mar 30, 2024

Bis correct

Alex1778
Apr 10, 2024

B is correct answer.

otakuinside
Sep 29, 2024

The variable must be declared aswell, another thing is that you have to assign a value to it. But the declaration is mandatory. At least this is my understanding of what the question says.