HashiCorp Terraform Associate 004 Practice Test Questions and Exam Dumps Part14 Q261-280

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


Q261. Which Terraform function returns a list containing numbers from a starting value up to an ending value

  1. chunklist
  2. setproduct
  3. index
  4. range

Correct Answer: 4. range

Explanation

The range function generates a list of numbers based on a starting value an ending value and an optional step value. chunklist divides an existing list into smaller groups. setproduct creates combinations from multiple collections. index finds the position of a value in a list. range is therefore the correct answer because it can produce predictable numeric sequences for Terraform expressions. It is useful when configuration needs calculated indexes or repeated numeric values. Users should ensure that generated ranges remain reasonably sized because very large collections can make configuration evaluation harder to understand and manage.

Q262. Which Terraform function returns a list with null values removed

  1. flatten
  2. compact
  3. distinct
  4. reverse

Correct Answer: 2. compact

Explanation

The compact function removes null values and empty string values from a list of strings. flatten combines nested lists into one list. distinct removes duplicate elements while preserving the remaining order. reverse changes the order of list elements. compact is therefore the correct answer because conditionally generated string lists may contain values that should not be passed to a resource or module. Cleaning the collection before further use can simplify later expressions. Users should understand the accepted input type because compact is designed for string collections rather than arbitrary complex object collections.

Q263. Which Terraform argument can document the purpose of an input variable

  1. description
  2. default
  3. nullable
  4. sensitive

Correct Answer: 1. description

Explanation

The description argument explains the purpose and expected meaning of an input variable. default supplies a fallback value. nullable controls whether null is accepted. sensitive marks the value so Terraform suppresses it from normal display. description is therefore the correct answer because reusable modules should clearly document what callers are expected to provide. Good descriptions improve module usability and reduce mistakes by explaining business meaning units or valid usage. Documentation does not replace strong type constraints or validation, so well designed variables should combine clear descriptions with appropriate technical restrictions.

Q264. Which Terraform function returns a list with duplicate values removed while preserving order

  1. toset
  2. compact
  3. distinct
  4. sort

Correct Answer: 3. distinct

Explanation

The distinct function removes duplicate elements from a list while preserving the order of the first occurrence of each remaining value. toset also removes duplicates but converts the collection into an unordered set. compact removes null or empty string values from suitable lists. sort orders strings lexically. distinct is therefore the correct answer because some configurations need unique values while still preserving list ordering. This can be useful when order has meaning for downstream expressions or provider arguments. Users should choose between distinct and toset according to whether maintaining positional order is important.

Q265. Which Terraform argument provides a fallback value when an input variable is not assigned

  1. default
  2. validation
  3. description
  4. sensitive

Correct Answer: 1. default

Explanation

The default argument supplies a value when the caller does not explicitly assign an input variable. validation defines rules that supplied values must satisfy. description documents the variable. sensitive marks the value for reduced display. default is therefore the correct answer because reusable modules often need optional inputs with sensible fallback behavior. A variable without a default is normally required unless another supported mechanism supplies its value. Defaults should be chosen carefully because hidden assumptions can make modules harder to understand if callers are unaware of the value that Terraform will use automatically.

Q266. Which Terraform block reads information from a provider without creating a managed object

  1. resource
  2. variable
  3. output
  4. data

Correct Answer: 4. data

Explanation

A data block reads information from a provider without declaring that Terraform should create or manage the underlying remote object. Resource blocks represent managed infrastructure. Variable blocks define configurable inputs. Output blocks expose selected values. data is therefore the correct answer because Terraform can use existing infrastructure or service information as input to managed resources. For example a data source can discover an existing network image or account setting. The exact available data sources depend on the provider, and Terraform may refresh them during planning so current information can influence proposed infrastructure changes.

Q267. Which Terraform function returns a list of all values from a map

  1. keys
  2. values
  3. lookup
  4. zipmap

Correct Answer: 2. values

Explanation

The values function returns the values stored in a map as a list ordered according to the map sorted keys. keys returns the map keys. lookup retrieves one value by a specified key. zipmap constructs a map from separate key and value lists. values is therefore the correct answer because some Terraform expressions need to transform a map into a list for further processing. When the association between keys and values remains important it is usually better to keep the original map because converting to a list removes the direct key relationship from the resulting value.

Q268. Which Terraform variable type stores true or false values

  1. string
  2. number
  3. bool
  4. object

Correct Answer: 3. bool

Explanation

The bool type stores boolean values that are either true or false. string stores text. number stores numeric values. object represents a structured collection of named attributes. bool is therefore the correct answer because Terraform configurations frequently use boolean inputs to enable or disable optional behavior. Boolean variables are clearer than string values such as yes or no because Terraform can enforce the type directly. Module authors should still use meaningful variable names and descriptions so callers understand exactly what enabling or disabling the value changes in the resulting infrastructure.

Q269. Which Terraform function returns the keys of a map as a sorted list

  1. values
  2. lookup
  3. merge
  4. keys

Correct Answer: 4. keys

Explanation

The keys function returns the keys from a map as a lexically sorted list. values returns map values according to the same key ordering. lookup retrieves one value from a map. merge combines multiple maps or objects. keys is therefore the correct answer because Terraform expressions sometimes need to iterate over or transform only the key names from a map. Although the function returns a predictable list order, resource identity should normally rely on stable map keys directly through for_each rather than converting them to numeric positions unnecessarily.

Q270. Which Terraform function returns the number of bytes in a string when measured as UTF encoded text

  1. length
  2. strrev
  3. strlen
  4. byteslength

Correct Answer: 1. length

Explanation

The length function returns the number of characters in a Terraform string and also returns the number of elements in supported collections. The other listed names are not the standard Terraform function for this purpose. length is therefore the correct answer among these options because validation logic frequently needs to check the size of names identifiers or collection values. Users should understand that character count and byte count are not always identical for every possible Unicode character. Provider specific limits should therefore be interpreted carefully when a remote service defines restrictions in bytes rather than characters.

Q271. Which Terraform argument allows a variable value to be hidden from normal output when it contains a secret

  1. nullable
  2. default
  3. sensitive
  4. validation

Correct Answer: 3. sensitive

Explanation

The sensitive argument marks a variable as sensitive so Terraform avoids displaying its value in many normal CLI contexts. nullable controls whether null is accepted. default provides a fallback value. validation defines custom input rules. sensitive is therefore the correct answer because passwords tokens and similar values should not appear casually in terminal output. Marking a variable sensitive does not prevent the value from being stored in Terraform state unless an ephemeral mechanism is also used where supported. State and plan files must therefore still be protected with appropriate access controls.

Q272. Which Terraform command option suppresses colored terminal output

  1. compact warnings
  2. no color
  3. input false
  4. refresh false

Correct Answer: 2. no color

Explanation

The no color option disables ANSI color codes in Terraform command output. compact warnings changes how warnings are displayed. input false prevents interactive prompts for missing input. refresh false skips remote refresh during supported planning workflows. no color is therefore the correct answer because automation systems and log processors often need plain text without terminal formatting characters. This option changes only presentation and does not affect planning state management provider behavior or infrastructure changes. It is commonly useful in continuous integration logs or when redirecting Terraform output into text processing tools.

Q273. Which Terraform function returns the value associated with a map key and supports a fallback

  1. values
  2. keys
  3. element
  4. lookup

Correct Answer: 4. lookup

Explanation

The lookup function retrieves the value associated with a specified map key and can optionally return a fallback when the key is absent. values returns all map values. keys returns all map keys. element retrieves an item from a list by position. lookup is therefore the correct answer because modules often select environment or region specific settings from a map. A fallback can simplify optional configuration, but important missing values may be better handled with validation so an incorrect key does not silently select a configuration the caller did not intend.

Q274. Which Terraform function returns the first element of a list after sorting it lexically

  1. min
  2. sort combined with element selection
  3. lookup
  4. values

Correct Answer: 2. sort combined with element selection

Explanation

Terraform does not provide a separate first sorted string function, so sorting a list and then selecting the first element is the appropriate approach. min works with numeric arguments rather than lexical string lists. lookup operates on maps. values extracts map values. sort combined with element selection is therefore the correct answer because Terraform expressions can compose multiple functions to achieve more specific transformations. Users should keep composed expressions readable and may assign intermediate results to local values when the final expression becomes difficult to understand or appears repeatedly throughout the configuration.

Q275. Which Terraform block declares an output that callers of a module can reference

  1. output
  2. locals
  3. resource
  4. data

Correct Answer: 1. output

Explanation

An output block exposes a value from a module so users or parent modules can reference it. locals defines internal reusable expressions. resource declares managed infrastructure. data reads provider information. output is therefore the correct answer because modules need a controlled interface for returning important values such as identifiers hostnames or network addresses. A child module output can be referenced by its parent without exposing the child module internal resource structure directly. Outputs can also include descriptions and sensitivity settings to improve documentation and protect confidential values.

Q276. Which Terraform function calculates the SHA256 hash of a local file in hexadecimal form

  1. filebase64sha256
  2. sha256
  3. filesha256
  4. base64sha256

Correct Answer: 3. filesha256

Explanation

The filesha256 function reads a local file and returns the SHA256 hash of its contents in hexadecimal form. filebase64sha256 returns the same type of hash encoded with Base64 representation. sha256 hashes a supplied string rather than directly reading a file. base64sha256 hashes a string and returns Base64 output. filesha256 is therefore the correct answer because providers sometimes use file checksums to detect artifact changes. The referenced file must already exist during configuration evaluation, and the resulting hash should be treated as a fingerprint rather than as encrypted file content.

Q277. Which Terraform type stores an unordered collection of unique values

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

Correct Answer: 2. set

Explanation

A set stores unique values without meaningful ordering. A tuple is an ordered sequence whose positions can have different types. A list is an ordered collection with a common element type. An object stores named attributes with defined types. set is therefore the correct answer because Terraform often uses sets when only membership matters and duplicate values should be removed. Sets work well with for_each when the elements are strings. Users should avoid relying on element positions because Terraform sets are intentionally unordered and do not support stable numeric indexing.

Q278. Which HCP Terraform feature can connect workspaces to version controlled configuration repositories

  1. State locking
  2. CLI configuration
  3. VCS integration
  4. Provider mirror

Correct Answer: 4. VCS integration

Explanation

VCS integration connects an HCP Terraform workspace with a supported version control repository so configuration changes can trigger managed Terraform workflows. State locking protects shared state. CLI configuration controls Terraform client behavior. Provider mirrors distribute provider packages. VCS integration is therefore the correct answer because infrastructure changes can follow normal code review and repository processes before they are planned or applied. Teams can use repository branches and pull request workflows to review configuration changes while HCP Terraform manages runs according to workspace permissions and organizational policies.

Q279. Which Terraform function returns the number of elements in a set

  1. distinct
  2. values
  3. length
  4. count

Correct Answer: 3. length

Explanation

The length function returns the number of elements in a set as well as other supported collections. distinct removes duplicates from a list. values extracts values from a map. count is a meta argument rather than a general function for measuring a collection. length is therefore the correct answer because Terraform expressions often need to determine whether a collection is empty or how many values it contains. The result can participate in conditions validations or calculations. Users should still avoid using collection size as a substitute for stable resource identity when for_each would provide clearer keys.

Q280. Which Terraform block allows reusable expressions to be assigned names inside a module

  1. locals
  2. output
  3. terraform
  4. resource

Correct Answer: 1. locals

Explanation

A locals block defines named local values that can be referenced elsewhere within the same Terraform module. Output blocks expose values outside the module. The terraform block defines Terraform level settings. Resource blocks declare managed infrastructure. locals is therefore the correct answer because repeated expressions can be calculated once and then referenced by a meaningful name. Local values improve readability for derived names tags conditions and transformed collections. They are internal to the module and cannot be assigned directly by callers in the way input variables can.