HashiCorp Terraform Associate Exam Practice Questions (P. 4)
- Full Access (358 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
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?
- Aservers = num_servers
- Bservers = variable.num_servers
- Cservers = var(num_servers)
- Dservers = var.num_serversMost Voted
Correct Answer:
A
A

The correct syntax for passing an input variable to a module in Terraform is by prefixing the variable name with `var.`. This establishes that the value being passed is an already defined variable. For instance, if the variable `num_servers` is assigned a value within a module context, it should be correctly integrated as `servers = var.num_servers`. This notation correctly references the value held in the `num_servers` variable outside the module, enabling it to be used within the module under a different alias, in this case, `servers`. Remember, distinguishing between variable definition and usage contexts is crucial for correct Terraform syntax.
send
light_mode
delete
Question #32
A Terraform provisioner must be nested inside a resource configuration block.
- ATrueMost Voted
- BFalse
Correct Answer:
A
Most provisioners require access to the remote resource via SSH or WinRM, and expect a nested connection block with details about how to connect.
Reference:
https://www.terraform.io/docs/language/resources/provisioners/connection.html
A
Most provisioners require access to the remote resource via SSH or WinRM, and expect a nested connection block with details about how to connect.
Reference:
https://www.terraform.io/docs/language/resources/provisioners/connection.html
send
light_mode
delete
Question #33
Terraform can run on Windows or Linux, but it requires a Server version of the Windows operating system.
- ATrue
- BFalseMost Voted
Correct Answer:
B
B

Terraform is indeed platform-agnostic, meaning it doesn't require a specific operating system or version to function properly. It's compatible with both Windows and Linux and does not necessitate a Server version of Windows. You can run Terraform on regular consumer versions like Windows 10 as long as the binary is installed and correctly configured in the system's PATH. This flexibility helps ensure Terraform can be used in a variety of environments without specific hardware or software dependencies.
send
light_mode
delete
Question #34
What does the default "local" Terraform backend store?
- Atfplan files
- BTerraform binary
- CProvider plugins
- DState fileMost Voted
Correct Answer:
D
The local backend stores state on the local filesystem, locks that state using system APIs, and performs operations locally.
Reference:
https://www.terraform.io/docs/language/settings/backends/local.html
D
The local backend stores state on the local filesystem, locks that state using system APIs, and performs operations locally.
Reference:
https://www.terraform.io/docs/language/settings/backends/local.html
send
light_mode
delete
Question #35
You have multiple team members collaborating on infrastructure as code (IaC) using Terraform, and want to apply formatting standards for readability.
How can you format Terraform HCL (HashiCorp Configuration Language) code according to standard Terraform style convention?
How can you format Terraform HCL (HashiCorp Configuration Language) code according to standard Terraform style convention?
- ARun the terraform fmt command during the code linting phase of your CI/CD processMost Voted
- BDesignate one person in each team to review and format everyone's code
- CManually apply two spaces indentation and align equal sign "=" characters in every Terraform file (*.tf)
- DWrite a shell script to transform Terraform files using tools such as AWK, Python, and sed
Correct Answer:
C
✑ Indent two spaces for each nesting level.
✑ When multiple arguments with single-line values appear on consecutive lines at the same nesting level, align their equals signs.
Reference:
https://www.terraform.io/docs/language/syntax/style.html
C
✑ Indent two spaces for each nesting level.
✑ When multiple arguments with single-line values appear on consecutive lines at the same nesting level, align their equals signs.
Reference:
https://www.terraform.io/docs/language/syntax/style.html
send
light_mode
delete
Question #36
What value does the Terraform Cloud/Terraform Enterprise private module registry provide over the public Terraform Module Registry?
- AThe ability to share modules with public Terraform users and members of Terraform Enterprise Organizations
- BThe ability to tag modules by version or release
- CThe ability to restrict modules to members of Terraform Cloud or Enterprise organizationsMost Voted
- DThe ability to share modules publicly with any user of Terraform
Correct Answer:
D
Terraform Registry is an index of modules shared publicly using this protocol. This public registry is the easiest way to get started with Terraform and find modules created by others in the community.
Reference:
https://www.terraform.io/docs/language/modules/sources.html
D
Terraform Registry is an index of modules shared publicly using this protocol. This public registry is the easiest way to get started with Terraform and find modules created by others in the community.
Reference:
https://www.terraform.io/docs/language/modules/sources.html
send
light_mode
delete
Question #37
Which task does terraform init not perform?
- ASources all providers present in the configuration and ensures they are downloaded and available locally
- BConnects to the backend
- CSources any modules and copies the configuration locally
- DValidates all required variables are presentMost Voted
Correct Answer:
D
Reference:
https://www.terraform.io/docs/cli/commands/init.html
D
Reference:
https://www.terraform.io/docs/cli/commands/init.html

send
light_mode
delete
Question #38
You have declared a variable called var.list which is a list of objects that all have an attribute id.
Which options will produce a list of the IDs? (Choose two.)
Which options will produce a list of the IDs? (Choose two.)
- A{ for o in var.list : o => o.id }
- Bvar.list[*].idMost Voted
- C[ var.list[*].id ]
- D[ for o in var.list : o.id ]Most Voted
Correct Answer:
AB
AB

In Terraform, to extract a list of IDs from a list of objects, two proficient methods exist. The notation `var.list[*].id` efficiently utilizes the splat operator, which gathers the id attributes from all objects in the list, thereby producing a straightforward list of IDs. Similarly, the list comprehension `[for o in var.list : o.id]` methodically iterates over each object in the list and extracts the id attribute. Both methods are valid and deliver a similar result: a list of all IDs present in the objects of `var.list`.
send
light_mode
delete
Question #39
Which argument(s) is (are) required when declaring a Terraform variable?
- Atype
- Bdefault
- Cdescription
- DAll of the above
- ENone of the aboveMost Voted
Correct Answer:
B
The variable declaration can also include a default argument.
Reference:
https://www.terraform.io/docs/language/values/variables.html
B
The variable declaration can also include a default argument.
Reference:
https://www.terraform.io/docs/language/values/variables.html
send
light_mode
delete
Question #40
When using a module block to reference a module stored on the public Terraform Module Registry such as:

How do you specify version 1.0.0?

How do you specify version 1.0.0?
- AModules stored on the public Terraform Module Registry do not support versioning
- BAppend ?ref=v1.0.0 argument to the source path
- CAdd version = "1.0.0" attribute to module blockMost Voted
- DNothing ג€" modules stored on the public Terraform Module Registry always default to version 1.0.0
Correct Answer:
C
C
send
light_mode
delete
All Pages