Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 31


Which of the following is the correct way to pass the value in the variable num_servers into a module with the input servers?

Show Answer
Correct Answer: D

To pass the value from the variable num_servers into a module with the input servers, you should use the syntax var.num_servers. The var namespace is used to reference input variables in Terraform. Therefore, the correct way to reference the variable is servers = var.num_servers.

Discussion

24 comments
Sign in to comment
tipzzz
Apr 24, 2022

D for sure

vitasacOption: D
Apr 29, 2022

Yes I'm agree D

BereOption: D
Jul 29, 2023

In Terraform, variables are referred to using the syntax var.<variable_name>. Here, var is a special namespace that contains all input variables. For example, if you have a variable named num_servers in your configuration and you want to pass it to a module, you would do it like this: variable "num_servers" { description = "The number of servers to create" default = 5 } module "server_module" { source = "app.terraform.io/example/server" version = "1.0.0" servers = var.num_servers } In the above example, the input variable num_servers is defined with a default value of 5. Then, the server_module is being called and the servers argument is being set to the value of var.num_servers, which is 5.

ItaloVinodiOption: D
May 13, 2022

D is the right one

EltoothOption: D
Jul 6, 2022

D is correct answer : var.NAME "Within the module that declared a variable, its value can be accessed from within expressions as var.<NAME>, where <NAME> matches the label given in the declaration block: Note: Input variables are created by a variable block, but you reference them as attributes on an object named var." https://www.terraform.io/language/values/variables#using-input-variable-values

prince1234Option: D
Aug 7, 2022

I am thinking these supplied answer want to engage discussions .

acheiron
Mar 17, 2023

I doubt we're seeing a deliberate educational tactic at work here. I rather suspect that data from a single person's attempt to pass the exam was provided as input and that's it. The answers marked "correct" are not affected by community votes or an attempt to prompt discussion: only by the initial dataset.

DKwork
Jun 23, 2023

If that were indeed the case, poor chap failed miserably.

DKwork
Jun 23, 2023

If that were indeed the case, poor chap failed miserably.

RVivekOption: D
Sep 22, 2022

D to pass a value to a module the syntax is <child module variable name > = <value> Here child module variable name is servers to reference the value of a variable in main/root module var. <name_of _the varibale>

Tomcrui1234589Option: D
Aug 7, 2022

D for sure. Variables are called using var.<variable_name> inside the resource arguments

najslejdiOption: D
Aug 24, 2022

D correct

kartikjena31
Jan 17, 2023

I also go with D

thor7Option: D
Mar 29, 2023

var.num_servers is correct and full answer

Bluemoon22
Apr 24, 2023

D, servers = var.num_servers

Cololand
May 8, 2024

D - Who even marks the right answers at examtopics?

yuvifoseOption: D
Jul 18, 2022

D for sure!

lalgebala
Nov 16, 2022

D for Sure

Power123
Mar 28, 2023

D is the ans

Power123
Mar 30, 2023

Ans is D

Ni33Option: D
May 8, 2023

D is the one

Shane_COption: D
Jul 4, 2023

D is correct

Kizerfor
Aug 26, 2023

D for sure

ghostGuiggsOption: D
Nov 2, 2023

D is the answer

enookOption: D
Jan 3, 2024

DDDDDDD

kanikachanderOption: D
Aug 3, 2024

D for sure

kanika_skOption: D
Nov 22, 2024

in terraform we need to use variables defined as var.<variable_name>