View Full HashiCorp Terraform Associate 004 Exam Dumps and Practice Test Dumps.
Q141. Which Terraform function returns the absolute path of a file system path
- basename
- abspath
- dirname
- pathexpand
Correct Answer: 2. abspath
Explanation
The abspath function converts a relative file system path into an absolute path. basename returns only the final component of a path. dirname returns the directory portion. pathexpand expands a home directory reference when present. abspath is therefore the correct answer because Terraform configurations sometimes need a complete path when referencing local files or external tools. Path based logic should be used carefully in reusable modules because execution environments may differ between developers automation systems and HCP Terraform. Portable modules should avoid unnecessary assumptions about local directory layouts whenever possible.
Q142. Which command creates a new Terraform CLI workspace and selects it
- terraform workspace show
- terraform workspace list
- terraform workspace select
- terraform workspace new
Correct Answer: 4. terraform workspace new
Explanation
terraform workspace new creates a new CLI workspace and makes it the active workspace. terraform workspace show displays the currently selected workspace. terraform workspace list shows available workspaces. terraform workspace select switches to a workspace that already exists. terraform workspace new is therefore the correct answer because each CLI workspace maintains a separate state instance for the same configuration. Users should remember that workspaces are most appropriate when infrastructure configurations remain largely similar. Separate root configurations may be more suitable when environments require substantially different architecture credentials or governance.
Q143. Which Terraform function returns the values associated with matching keys from a map
- lookup
- merge
- keys
- values
Correct Answer: 1. lookup
Explanation
The lookup function retrieves a value from a map using a specified key and can optionally return a default when the key is absent. merge combines maps or objects. keys returns all map keys. values returns all map values. lookup is therefore the correct answer because Terraform configurations often need to select a setting based on an environment region or other named key. Using a sensible default can make configuration flexible, although important missing values should sometimes produce validation errors rather than silently falling back to an unexpected configuration.
Q144. Which Terraform feature can create one resource instance for each map entry
- count
- depends_on
- for_each
- lifecycle
Correct Answer: 3. for_each
Explanation
for_each creates separate resource or module instances from entries in a map or elements in a set of strings. count creates instances using numeric indexes. depends_on declares explicit dependencies. lifecycle modifies selected resource behavior. for_each is therefore the correct answer because each instance receives a stable key that can correspond to meaningful infrastructure identifiers. This often makes configuration changes easier to manage than positional indexes. Users should choose stable keys because changing a key changes the Terraform resource address and may cause Terraform to destroy one instance and create another.
Q145. Which Terraform file contains provider selections and checksums
- terraform.lock.hcl
- terraform.tfvars
- terraform.tfstate
- main.tf
Correct Answer: 1. terraform.lock.hcl
Explanation
terraform.lock.hcl is the dependency lock file that records selected provider versions and package checksums. terraform.tfvars commonly contains input variable assignments. terraform.tfstate stores state information when local state is used. main.tf is simply a conventional configuration file name. terraform.lock.hcl is therefore the correct answer because it helps ensure consistent provider installation across users and automation environments. Teams should normally commit the lock file to version control so provider selections remain predictable until an intentional upgrade is performed and reviewed.
Q146. Which Terraform function converts YAML text into Terraform values
- yamlencode
- jsondecode
- templatefile
- yamldecode
Correct Answer: 4. yamldecode
Explanation
The yamldecode function parses YAML formatted text and converts it into Terraform values such as maps lists strings numbers and booleans. yamlencode performs the reverse operation. jsondecode parses JSON rather than YAML. templatefile renders template content using supplied variables. yamldecode is therefore the correct answer because Terraform configurations may consume structured YAML files containing settings that need to be transformed or referenced. Users should ensure the YAML structure maps cleanly to supported Terraform value types and should avoid using external configuration files when ordinary Terraform variables would provide a clearer module interface.
Q147. Which command checks whether Terraform configuration files are formatted correctly without rewriting them
- terraform validate
- terraform fmt with check
- terraform plan
- terraform show
Correct Answer: 2. terraform fmt with check
Explanation
terraform fmt with check verifies whether configuration files already follow Terraform standard formatting without rewriting them. terraform validate checks syntax and internal consistency rather than formatting style. terraform plan previews infrastructure changes. terraform show displays state or plan information. terraform fmt with check is therefore the correct answer because automated pipelines can verify formatting and fail when configuration needs normalization. Teams can then run terraform fmt locally before committing changes. Consistent formatting improves readability and reduces unnecessary formatting differences during code review.
Q148. Which Terraform function returns a selected element from a list using an index
- index
- one
- element
- contains
Correct Answer: 3. element
Explanation
The element function retrieves an item from a list using a numeric index and supports index wrapping behavior. index performs the opposite task by finding the position of a specified value. one extracts the only element from a collection containing zero or one item. contains checks whether a collection includes a value. element is therefore the correct answer because Terraform expressions may need to select one item from an ordered collection. Users should avoid relying too heavily on positional indexes when stable named keys would make infrastructure relationships easier to understand and maintain.
Q149. Which Terraform block configures connection details for a remote exec provisioner
- provider
- backend
- lifecycle
- connection
Correct Answer: 4. connection
Explanation
A connection block defines connection information used by provisioners such as remote exec or file when Terraform must communicate directly with a remote machine. Provider blocks configure provider access. Backend blocks configure state storage. Lifecycle blocks control resource lifecycle behavior. connection is therefore the correct answer because remote provisioners may require details such as host user authentication or connection type. Provisioners and direct remote connections should generally be used only when provider native mechanisms or dedicated configuration management approaches cannot satisfy the requirement.
Q150. Which Terraform function returns the position of a value inside a list
- index
- element
- length
- lookup
Correct Answer: 1. index
Explanation
The index function searches a list and returns the numeric position of a specified value. element retrieves a list item at a given position. length returns the number of elements. lookup retrieves a value from a map using a key. index is therefore the correct answer because Terraform expressions sometimes need to determine where a particular item appears within an ordered collection. The function reports an error if the requested value is not present, so configurations should validate assumptions or use alternative logic when the value may legitimately be absent.
Q151. Which Terraform feature allows resources to be created conditionally by setting the instance count to zero
- lifecycle
- provider alias
- count
- backend
Correct Answer: 3. count
Explanation
The count meta argument can be assigned zero to create no instances or a positive integer to create that many instances. lifecycle controls selected resource behavior. Provider aliases choose alternate provider configurations. Backend configuration controls state storage. count is therefore the correct answer because conditional expressions can determine whether a resource should exist. This pattern is common for simple optional resources. Users should remember that counted resources are addressed with numeric indexes and that for_each may be preferable when optional instances have meaningful stable keys.
Q152. Which function returns true when a collection contains a specified value
- anytrue
- contains
- can
- distinct
Correct Answer: 2. contains
Explanation
The contains function checks whether a list tuple or set includes a specified value and returns a boolean result. anytrue evaluates whether at least one boolean element is true. can checks whether an expression can be evaluated successfully. distinct removes duplicate list values. contains is therefore the correct answer because validation rules and conditional expressions often need to test membership in an approved collection. For example a module can verify that a requested environment or region appears in a defined set of supported values before using it in infrastructure configuration.
Q153. Which block can define minimum provider versions required by a Terraform module
- required_providers
- provider alias
- output
- resource
Correct Answer: 1. required_providers
Explanation
The required_providers block declares provider source addresses and version constraints required by a Terraform module. Provider aliases configure alternate instances after a provider requirement exists. Output blocks expose values. Resource blocks declare managed objects. required_providers is therefore the correct answer because modules should state which provider implementations and versions they are compatible with. Sensible constraints help avoid accidental use of incompatible provider releases while still allowing tested upgrades. The dependency lock file then records the specific provider selections used by the root configuration.
Q154. Which Terraform command option can request replacement of a resource during planning
- target
- parallelism
- refresh only
- replace
Correct Answer: 4. replace
Explanation
The replace option tells Terraform to plan replacement of a selected resource instance even when its configuration does not otherwise require recreation. target narrows planning to selected objects. parallelism controls concurrent operations. refresh only focuses on updating state to reflect remote changes. replace is therefore the correct answer because administrators may occasionally need to recreate an unhealthy or incorrectly provisioned resource while keeping its configuration unchanged. The generated plan should always be reviewed because replacement normally involves destruction and creation and can affect availability or stored data.
Q155. Which HCP Terraform feature can centrally manage organization wide credentials and common values
- State list
- Variable sets
- Provider aliases
- CLI workspaces
Correct Answer: 2. Variable sets
Explanation
Variable sets allow HCP Terraform organizations to define Terraform variables or environment variables once and apply them to multiple workspaces or projects according to scope. State list is a CLI command. Provider aliases configure alternate provider instances. CLI workspaces manage separate state instances locally or through a backend. Variable sets is therefore the correct answer because teams often need to distribute common configuration or credentials consistently without duplicating values manually in every workspace. Sensitive values should be marked and scoped carefully so only required workspaces can access them.
Q156. Which Terraform function returns a substring from a string using an offset and length
- format
- regex
- substr
- join
Correct Answer: 3. substr
Explanation
The substr function returns part of a string beginning at a specified offset and continuing for a specified length. format creates formatted strings. regex applies a regular expression. join combines strings from a collection using a separator. substr is therefore the correct answer because Terraform configurations may need to extract predictable segments from naming values identifiers or other text. Users should use string slicing carefully because infrastructure naming conventions can become fragile when logic depends on fixed positions that may change as input values evolve.
Q157. Which feature allows HCP Terraform to estimate infrastructure costs before an apply when supported
- Run triggers
- State locking
- Private registry
- Cost estimation
Correct Answer: 4. Cost estimation
Explanation
Cost estimation can provide an estimated infrastructure cost for supported resources during the HCP Terraform run workflow before changes are applied. Run triggers connect workspace runs. State locking protects state from concurrent changes. Private registry distributes reusable components. Cost estimation is therefore the correct answer because infrastructure teams may want visibility into the financial effect of proposed changes before approving them. Estimates depend on supported providers resource types and pricing information, so they should be treated as planning guidance rather than guaranteed final billing values.
Q158. Which function combines a list of strings into one string using a separator
- concat
- join
- merge
- flatten
Correct Answer: 2. join
Explanation
The join function combines all strings in a list into one string and inserts the specified separator between them. concat combines lists. merge combines maps or objects. flatten transforms nested lists into a single list. join is therefore the correct answer because Terraform configurations often need to build names paths or formatted values from collection elements. The separator can be any required string. Users should still keep generated names predictable because changing naming logic may cause infrastructure replacements when providers treat resource names as immutable.
Q159. Which Terraform provisioner copies files from the Terraform execution host to a remote resource
- local exec
- remote exec
- file
- connection
Correct Answer: 3. file
Explanation
The file provisioner copies files or directory content from the machine running Terraform to a remote resource through a configured connection. local exec runs commands on the Terraform execution host. remote exec runs commands on the remote machine. connection defines communication details but does not copy files by itself. file is therefore the correct answer. Provisioners are generally considered a last resort because their side effects are difficult for Terraform to model reliably. Native provider capabilities or image based configuration are usually preferred when they can accomplish the same task.
Q160. Which Terraform function expands a home directory reference in a file system path
- pathexpand
- basename
- dirname
- abspath
Correct Answer: 1. pathexpand
Explanation
The pathexpand function expands a path beginning with a home directory reference into a corresponding file system path. basename returns the final path component. dirname returns the directory component. abspath converts a relative path into an absolute path. pathexpand is therefore the correct answer because local configuration sometimes refers to files stored beneath a user home directory. Reusable Terraform modules should avoid unnecessary dependence on user specific local paths because remote execution environments and automation systems may have different file system layouts.