HashiCorp Terraform Associate 004 Practice Test Questions and Exam Dumps Part5 Q81-100

View Full HashiCorp Terraform Associate 004 Exam Dumps and Practice Test Dumps.


Q81. Which Terraform value represents the intentional absence of a value

  1. false
  2. null
  3. zero
  4. empty

Correct Answer: 2. null

Explanation

null represents the absence or omission of a value in Terraform expressions. false is a boolean value and zero is a numeric value, so both still represent actual values. empty is not the general Terraform value used to represent absence. null is therefore the correct answer because Terraform can treat a null argument as though no value was provided in many contexts. This behavior is useful when optional configuration should be omitted conditionally. Users should understand the expected type of the surrounding expression because Terraform still performs type checking when null values participate in more complex expressions.

Q82. Which Terraform function returns the first expression that evaluates without an error

  1. length
  2. merge
  3. lookup
  4. try

Correct Answer: 4. try

Explanation

The try function evaluates expressions in order and returns the first one that does not produce an error. length calculates the size of a collection or string. merge combines maps or objects. lookup retrieves a map value using a key. try is therefore the correct answer because it can simplify handling of values whose structure may vary or whose attributes may not always exist. It should be used carefully because excessive error suppression can make configuration problems harder to understand. Clear data structures and explicit validation are usually preferable when the expected input shape is known.

Q83. Which function returns the first argument that is not null or an empty string

  1. coalesce
  2. flatten
  3. join
  4. keys

Correct Answer: 1. coalesce

Explanation

The coalesce function returns the first argument that is neither null nor an empty string. flatten transforms nested lists into a single list. join combines strings from a collection using a separator. keys returns the keys from a map. coalesce is therefore the correct answer because it is useful when configuration should select the first available value from several possible inputs. The arguments should have compatible types so Terraform can determine a valid result. This function can support defaults and fallback behavior without requiring a longer conditional expression for simple cases.

Q84. Which Terraform function converts a collection into a set

  1. tomap
  2. tostring
  3. toset
  4. tonumber

Correct Answer: 3. toset

Explanation

The toset function converts a compatible collection into a set value. tomap converts a value to a map. tostring converts a value to a string. tonumber converts a compatible value to a number. toset is therefore the correct answer because sets contain unique values and do not preserve duplicate elements. Sets are commonly useful with for_each when individual string values should become stable instance keys. Users should remember that sets are unordered, so configurations should not rely on a particular element position after conversion.

Q85. Which function converts a nested list structure into a single flat list

  1. flatten
  2. merge
  3. lookup
  4. zipmap

Correct Answer: 1. flatten

Explanation

The flatten function replaces nested list elements with their individual elements to produce a single list. merge combines maps or objects. lookup retrieves a value from a map. zipmap creates a map from separate key and value lists. flatten is therefore the correct answer because Terraform configurations sometimes generate nested collections through loops or module inputs and then need one list for further processing. It is especially useful before creating resources from combinations of values. Users should verify that the resulting structure still preserves the relationships required by the infrastructure design.

Q86. Which Terraform function tests whether an expression can be evaluated successfully

  1. contains
  2. regex
  3. try
  4. can

Correct Answer: 4. can

Explanation

The can function evaluates an expression and returns true when the expression succeeds or false when it produces an error. contains checks whether a collection contains a value. regex performs regular expression matching. try returns the first expression that succeeds rather than a boolean result. can is therefore the correct answer because it is useful in validation conditions where a configuration needs to test whether a conversion or expression is valid. It should generally be used for concise validation rather than broad error suppression across normal configuration logic.

Q87. Which variable feature restricts an input to a specific kind of value such as string or list

  1. output
  2. type constraint
  3. provider alias
  4. backend

Correct Answer: 2. type constraint

Explanation

A type constraint defines the kind of value an input variable accepts, such as string number bool list map set tuple or object. Output blocks expose values. Provider aliases select alternate provider configurations. Backend configuration controls state storage behavior. type constraint is therefore the correct answer because it helps Terraform detect invalid inputs before those values are used in resource configuration. Strong type definitions improve module clarity and reliability because callers can understand the expected data structure. Complex object types can also describe structured inputs with several related attributes.

Q88. Which type feature allows an object attribute to be omitted by callers when it is not required

  1. sensitive
  2. default only
  3. optional
  4. depends_on

Correct Answer: 3. optional

Explanation

optional allows an attribute within an object type constraint to be omitted when callers do not need to provide it. sensitive changes how confidential values are displayed. A general default value is not itself the object type feature used to mark an individual attribute as optional. depends_on defines dependencies. optional is therefore the correct answer because reusable modules often need structured inputs where some attributes are required and others have defaults or may be omitted. This can improve module usability while still preserving strong type checking for the overall object structure.

Q89. Which command runs Terraform configuration tests defined for the current module

  1. terraform validate
  2. terraform plan
  3. terraform apply
  4. terraform test

Correct Answer: 4. terraform test

Explanation

terraform test executes Terraform test files associated with a module and evaluates configured assertions. terraform validate checks configuration syntax and internal consistency but does not execute the module test workflow. terraform plan previews infrastructure changes. terraform apply performs infrastructure changes. terraform test is therefore the correct answer because module authors can define automated tests that exercise configuration behavior and verify expected results. Tests can help detect regressions when modules evolve. Test configurations should be designed carefully because some test scenarios can create real infrastructure depending on how runs are configured.

Q90. Which file extension is used for Terraform test files

  1. tftest.hcl
  2. tfstate.hcl
  3. tfvars.hcl
  4. terraformtest.tf

Correct Answer: 1. tftest.hcl

Explanation

Terraform test files use the tftest.hcl extension and contain test definitions such as run blocks and assertions. tfstate.hcl is not the standard test file extension. tfvars files are used for variable assignments. terraformtest.tf is not the designated Terraform testing file format. tftest.hcl is therefore the correct answer because Terraform can discover these files and execute their test definitions with terraform test. Keeping tests close to reusable modules can help teams validate expected planning or application behavior when module configuration changes.

Q91. Which Terraform command outputs a visual dependency graph representation

  1. terraform show
  2. terraform graph
  3. terraform state list
  4. terraform providers

Correct Answer: 2. terraform graph

Explanation

terraform graph produces a representation of the dependency graph Terraform builds from configuration relationships. terraform show displays state or plan information. terraform state list lists resource addresses in state. terraform providers displays provider requirements. terraform graph is therefore the correct answer because it can help users inspect how Terraform understands dependencies between resources and other objects. The output is commonly compatible with graph visualization tools. This can be useful when troubleshooting unexpected dependency relationships, although normal resource references should usually make configuration dependencies clear without requiring graph inspection.

Q92. Which environment variable prefix can be used to assign Terraform input variables

  1. TERRAFORM_INPUT
  2. VAR_TF
  3. TF_VALUE
  4. TF_VAR_

Correct Answer: 4. TF_VAR_

Explanation

Terraform recognizes environment variables beginning with TF_VAR_ as values for matching input variables. The portion after the prefix corresponds to the Terraform variable name. TERRAFORM_INPUT, VAR_TF and TF_VALUE are not the standard input variable prefixes. TF_VAR_ is therefore the correct answer because environment variables provide one method of supplying configuration values without placing them directly inside Terraform files. Sensitive values still require appropriate environment security because process environments and automation logs may expose them if systems are configured carelessly.

Q93. Which file naming pattern causes Terraform to load variable values automatically

  1. Any text file
  2. provider.auto.hcl
  3. Files ending in auto.tfvars
  4. Files ending in state.vars

Correct Answer: 3. Files ending in auto.tfvars

Explanation

Terraform automatically loads variable definition files whose names end in auto.tfvars as well as supported JSON equivalents. Arbitrary text files are not loaded automatically. provider.auto.hcl and state.vars are not standard automatic variable file naming patterns. Files ending in auto.tfvars is therefore the correct answer because teams can separate groups of variable values without passing each file manually on the command line. Users should still understand variable precedence when several assignment methods are present. Sensitive credentials should be stored securely rather than committed to version control in ordinary variable files.

Q94. Which backend stores Terraform state on the local file system

  1. local backend
  2. remote backend only
  3. provider backend
  4. registry backend

Correct Answer: 1. local backend

Explanation

The local backend stores Terraform state on the local file system and performs operations from the local machine. Remote backends store state elsewhere or may provide additional remote capabilities depending on the backend. Provider backend and registry backend are not the relevant standard backend names. local backend is therefore the correct answer because it is the default style of state storage for simple local Terraform use. For collaborative environments remote state is usually more appropriate because team members need a shared authoritative state location and may require locking or centralized access controls.

Q95. Which HCP Terraform workflow can automatically start a run when configuration changes are committed to a connected repository

  1. Local state workflow
  2. VCS driven workflow
  3. Manual state editing
  4. Provider alias workflow

Correct Answer: 2. VCS driven workflow

Explanation

A VCS driven workflow connects an HCP Terraform workspace to a version control repository and can automatically queue Terraform runs when relevant configuration changes are committed. Local state workflow is not the feature used for repository triggered runs. Manual state editing should not drive normal infrastructure deployment. Provider aliases control provider configurations rather than execution workflows. VCS driven workflow is therefore the correct answer because infrastructure changes can follow code review and version control processes. Teams can review plans before apply according to workspace permissions and organizational workflow settings.

Q96. Which HCP Terraform object can group related workspaces for organization and access management

  1. Provider
  2. Module call
  3. Project
  4. State resource

Correct Answer: 3. Project

Explanation

A project in HCP Terraform groups related workspaces and can help organizations structure access and management boundaries. Providers connect Terraform to external platforms. Module calls reuse configuration. State resources represent managed infrastructure objects rather than organizational containers. Project is therefore the correct answer because organizations may have many workspaces belonging to different applications teams or infrastructure domains. Grouping them into projects can make permissions and administration easier to understand. Projects provide organizational structure while each workspace continues to maintain its own runs variables and state according to its configuration.

Q97. Which Terraform Registry capability can privately distribute reusable modules within an organization

  1. Public provider mirror only
  2. Local state file
  3. Backend migration
  4. Private module registry

Correct Answer: 4. Private module registry

Explanation

A private module registry provides a controlled location where an organization can publish discover version and consume reusable Terraform modules. A public provider mirror focuses on provider distribution rather than private organizational modules. Local state files and backend migration are unrelated to module publishing. Private module registry is therefore the correct answer because teams can share approved infrastructure patterns without exposing internal modules publicly. Versioned modules also make it easier for consumers to adopt changes deliberately rather than depending automatically on the latest source code in a repository.

Q98. Which command downloads and updates child modules without performing full backend initialization

  1. terraform providers
  2. terraform get
  3. terraform state pull
  4. terraform workspace show

Correct Answer: 2. terraform get

Explanation

terraform get downloads and updates child modules referenced by the current configuration. terraform providers displays provider requirements. terraform state pull retrieves state. terraform workspace show displays the active workspace name. terraform get is therefore the correct answer because module dependencies can be retrieved separately from the broader initialization behavior provided by terraform init. In normal workflows terraform init commonly handles module installation together with providers and backend initialization, but terraform get remains useful when the specific task is updating modules without repeating the full initialization process.

Q99. Which Terraform value type stores key and value pairs where keys are strings

  1. tuple
  2. set
  3. map
  4. list

Correct Answer: 3. map

Explanation

A map stores values associated with string keys. A tuple contains an ordered sequence whose elements can have individually defined types. A set stores unique unordered values. A list stores an ordered sequence of values with a common element type. map is therefore the correct answer because Terraform configurations often use maps for named settings such as tags environment options or lookup values. Maps are also convenient with for_each because stable string keys can become resource instance identifiers. Choosing stable keys helps avoid unnecessary resource address changes when values are updated.

Q100. Which Terraform language type stores an ordered sequence of values that may have different individual types

  1. tuple
  2. map
  3. set
  4. string

Correct Answer: 1. tuple

Explanation

A tuple is an ordered sequence in which each element can have its own defined type. A map associates string keys with values. A set is an unordered collection of unique values. A string stores text. tuple is therefore the correct answer because Terraform distinguishes structural types such as tuples and objects from collection types such as lists maps and sets. Tuples are commonly produced by expressions where Terraform knows the type of each position individually. Understanding Terraform types helps users write accurate variable constraints expressions and module interfaces while avoiding unexpected automatic conversions.