HashiCorp Terraform Associate (HashiCorp Certified: Terraform Associate) Practice Test 19

Question 180

During a design review, the requirement is to supply a single variable assignment when invoking plan or apply. Which option should the engineer select?

  1. terraform output -json
  2. terraform output -raw
  3. The -var option
  4. A child module output block

Explanation

Correct Answer

C:

Command-line -var assignments take high precedence and are useful for an explicit run-specific override; this directly meets the requirement to supply a single variable assignment when invoking plan or apply. By comparison, a child module output block is intended to make a child module's private resource attribute available to its caller, which is a different task from supply a single variable assignment when invoking plan or apply.

Incorrect Answers

A:

The JSON output mode serializes output values and metadata for automation; it can expose sensitive values and must be protected; this mechanism is useful when the job is to retrieve root outputs for integration with another program, whereas the current scenario requires the engineer to supply a single variable assignment when invoking plan or apply. These operations have different effects in the stated Terraform workflow.

B:

The -raw output mode prints a single string, number or boolean value in a script-friendly form and may reveal sensitive data; this mechanism is useful when the job is to extract a primitive output without the surrounding formatted representation, whereas the current scenario requires the engineer to supply a single variable assignment when invoking plan or apply. These operations have different effects in the stated Terraform workflow.

D:

A child module must explicitly export an output for its parent to access it through module.CHILD.OUTPUT; this mechanism is useful when the job is to make a child module's private resource attribute available to its caller, whereas the current scenario requires the engineer to supply a single variable assignment when invoking plan or apply. These operations have different effects in the stated Terraform workflow.

Question 181

A change request asks an engineer to retrieve the map values sorted by their corresponding keys. Which choice best implements the requested behavior?

  1. The values function
  2. The base64encode function
  3. The ternary conditional operator
  4. The upper function

Explanation

Correct Answer

A:

values returns a list of map values in lexical key order, not random map iteration order; this directly meets the requirement to retrieve the map values sorted by their corresponding keys. By comparison, the ternary conditional operator is intended to set a resource argument according to a boolean expression, which is a different task from retrieve the map values sorted by their corresponding keys.

Incorrect Answers

B:

base64encode applies a reversible encoding and should not be mistaken for encryption of secrets; this mechanism is useful when the job is to turn ordinary string content into Base64 text, whereas the current scenario requires the engineer to retrieve the map values sorted by their corresponding keys. These operations have different effects in the stated Terraform workflow.

C:

The condition ? value_a : value_b expression chooses a suitable branch without creating duplicate resource blocks; this mechanism is useful when the job is to set a resource argument according to a boolean expression, whereas the current scenario requires the engineer to retrieve the map values sorted by their corresponding keys. These operations have different effects in the stated Terraform workflow.

D:

upper transforms the letters of a string into uppercase without changing its underlying Terraform type; this mechanism is useful when the job is to convert an environment label to uppercase, whereas the current scenario requires the engineer to retrieve the map values sorted by their corresponding keys. These operations have different effects in the stated Terraform workflow.

Question 182

A Terraform module author requires a way to serialize a Terraform value into a valid JSON string. Which Terraform approach most directly fulfills that request?

  1. The templatefile function
  2. The for expression
  3. The cidrhost function
  4. The jsonencode function

Explanation

Correct Answer

D:

jsonencode converts Terraform values into JSON representation suitable for API fields expecting JSON text; this directly meets the requirement to serialize a Terraform value into a valid JSON string. By comparison, the templatefile function is intended to render a file containing template expressions with an object of variables, which is a different task from serialize a Terraform value into a valid JSON string.

Incorrect Answers

A:

templatefile reads a template and evaluates placeholders using the supplied variable map; this mechanism is useful when the job is to render a file containing template expressions with an object of variables, whereas the current scenario requires the engineer to serialize a Terraform value into a valid JSON string. These operations have different effects in the stated Terraform workflow.

B:

A for expression builds derived collection values, optionally filtering with an if clause and transforming keys or values; this mechanism is useful when the job is to transform a collection's elements into a new list or map, whereas the current scenario requires the engineer to serialize a Terraform value into a valid JSON string. These operations have different effects in the stated Terraform workflow.

C:

cidrhost computes a host address inside the given prefix from a numeric host index; this mechanism is useful when the job is to calculate an IP address at an offset within a CIDR range, whereas the current scenario requires the engineer to serialize a Terraform value into a valid JSON string. These operations have different effects in the stated Terraform workflow.

Question 183

An organization integrating Terraform with source control has a concrete implementation goal: evaluate a pull request's proposed changes without immediately applying them. What is the most appropriate Terraform mechanism?

  1. An API-driven workspace
  2. A speculative HCP plan
  3. A workspace variable
  4. A CLI-driven workspace

Explanation

Correct Answer

B:

HCP Terraform can perform speculative plans for VCS changes to preview impact before merge or approval; this directly meets the requirement to evaluate a pull request's proposed changes without immediately applying them. By comparison, an API-driven workspace is intended to start Terraform runs through an external automation integration, which is a different task from evaluate a pull request's proposed changes without immediately applying them.

Incorrect Answers

A:

HCP Terraform APIs can upload configuration versions and orchestrate runs programmatically; this mechanism is useful when the job is to start Terraform runs through an external automation integration, whereas the current scenario requires the engineer to evaluate a pull request's proposed changes without immediately applying them. These operations have different effects in the stated Terraform workflow.

C:

HCP Terraform workspaces can hold Terraform input variables and environment variables for run-time use; this mechanism is useful when the job is to supply a configuration input or environment value for HCP Terraform runs, whereas the current scenario requires the engineer to evaluate a pull request's proposed changes without immediately applying them. These operations have different effects in the stated Terraform workflow.

D:

A CLI workflow can send configuration from the Terraform CLI to HCP Terraform for workspace runs; this mechanism is useful when the job is to upload local configuration for execution through HCP Terraform rather than relying on Git webhooks, whereas the current scenario requires the engineer to evaluate a pull request's proposed changes without immediately applying them. These operations have different effects in the stated Terraform workflow.

Question 184

An engineer troubleshooting a .tf configuration needs to pick the first non-null and nonempty string among candidate values. Which feature or operation is the most direct match?

  1. The cidrsubnet function
  2. The coalesce function
  3. The flatten function
  4. The lookup function
  5. The dynamic block

Explanation

Correct Answer

B:

coalesce returns the first usable argument after skipping null or empty strings; it is not a boolean operator; this directly meets the requirement to pick the first non-null and nonempty string among candidate values. By comparison, the flatten function is intended to remove nested list layers to obtain a flat sequence, which is a different task from pick the first non-null and nonempty string among candidate values.

Incorrect Answers

A:

cidrsubnet derives a subnet CIDR using additional prefix bits and a network number, without provisioning a network resource; this mechanism is useful when the job is to calculate a nested network prefix from a parent CIDR range, whereas the current scenario requires the engineer to pick the first non-null and nonempty string among candidate values. These operations have different effects in the stated Terraform workflow.

C:

flatten recursively replaces nested lists with their constituent elements, while preserving ordered traversal; this mechanism is useful when the job is to remove nested list layers to obtain a flat sequence, whereas the current scenario requires the engineer to pick the first non-null and nonempty string among candidate values. These operations have different effects in the stated Terraform workflow.

D:

lookup(map, key, default) retrieves the selected key's value or the supplied default if the key does not exist; this mechanism is useful when the job is to read a map element and provide a fallback when the key is absent, whereas the current scenario requires the engineer to pick the first non-null and nonempty string among candidate values. These operations have different effects in the stated Terraform workflow.

E:

dynamic constructs blocks required by resource schemas; it does not create standalone Terraform resource declarations; this mechanism is useful when the job is to generate repeated nested blocks from a collection, whereas the current scenario requires the engineer to pick the first non-null and nonempty string among candidate values. These operations have different effects in the stated Terraform workflow.

Question 185

A new Terraform working directory has a concrete implementation goal: make resources use a common account without an explicit provider argument. What is the most appropriate Terraform mechanism?

  1. configuration_aliases in required_providers
  2. Explicit provider selection on data blocks
  3. A default provider configuration
  4. The providers map on a module call

Explanation

Correct Answer

C:

An unaliased provider block configures the default instance used by matching resources that do not override provider selection; this directly meets the requirement to make resources use a common account without an explicit provider argument. By comparison, explicit provider selection on data blocks is intended to read an object from a secondary account rather than the default account, which is a different task from make resources use a common account without an explicit provider argument.

Incorrect Answers

A:

A child module's required_providers entry uses configuration_aliases to advertise provider aliases referenced inside the module; this mechanism is useful when the job is to declare which alternate provider configurations a child module is allowed to receive, whereas the current scenario requires the engineer to make resources use a common account without an explicit provider argument. These operations have different effects in the stated Terraform workflow.

B:

A data block can set provider = aws.secondary to query through an alternate provider configuration; this mechanism is useful when the job is to read an object from a secondary account rather than the default account, whereas the current scenario requires the engineer to make resources use a common account without an explicit provider argument. These operations have different effects in the stated Terraform workflow.

D:

The module call's providers argument maps the child's expected provider configuration name to a provider configuration available in the parent; this mechanism is useful when the job is to pass an aliased provider configuration into a child module, whereas the current scenario requires the engineer to make resources use a common account without an explicit provider argument. These operations have different effects in the stated Terraform workflow.

Question 186

A provider configuration review needs to use two unrelated service APIs in one root configuration. Which feature or operation is the most direct match?

  1. Separate required provider names
  2. An aliased provider instance
  3. A default provider configuration
  4. Provider configuration at the root

Explanation

Correct Answer

A:

List both plugins under required_providers and configure each service's provider independently as needed; this directly meets the requirement to use two unrelated service APIs in one root configuration. By comparison, provider configuration at the root is intended to supply provider configurations from the root module to reusable child modules, which is a different task from use two unrelated service APIs in one root configuration.

Incorrect Answers

B:

Declare an aliased provider configuration and assign provider = provider_name.alias on resources that need the alternate region; this mechanism is useful when the job is to create resources in a second region using the same provider type, whereas the current scenario requires the engineer to use two unrelated service APIs in one root configuration. These operations have different effects in the stated Terraform workflow.

C:

An unaliased provider block configures the default instance used by matching resources that do not override provider selection; this mechanism is useful when the job is to make resources use a common account without an explicit provider argument, whereas the current scenario requires the engineer to use two unrelated service APIs in one root configuration. These operations have different effects in the stated Terraform workflow.

D:

Reusable child modules should primarily declare provider requirements and receive configurations from callers rather than embedding fixed credentials; this mechanism is useful when the job is to supply provider configurations from the root module to reusable child modules, whereas the current scenario requires the engineer to use two unrelated service APIs in one root configuration. These operations have different effects in the stated Terraform workflow.

Question 187

A Terraform module author needs to ask the caller for a value when no default should be assumed. Which feature or operation is the most direct match?

  1. A sensitive output
  2. The -var option
  3. The -var-file option
  4. A terraform.tfvars file
  5. A required input variable

Explanation

Correct Answer

E:

A variable block without a default requires a provided value if Terraform cannot otherwise obtain one; this directly meets the requirement to ask the caller for a value when no default should be assumed. By comparison, the -var option is intended to supply a single variable assignment when invoking plan or apply, which is a different task from ask the caller for a value when no default should be assumed.

Incorrect Answers

A:

Marking an output sensitive redacts ordinary CLI presentation, but does not by itself prevent storage in state; this mechanism is useful when the job is to hide a secret-like output from Terraform's usual human-readable display, whereas the current scenario requires the engineer to ask the caller for a value when no default should be assumed. These operations have different effects in the stated Terraform workflow.

B:

Command-line -var assignments take high precedence and are useful for an explicit run-specific override; this mechanism is useful when the job is to supply a single variable assignment when invoking plan or apply, whereas the current scenario requires the engineer to ask the caller for a value when no default should be assumed. These operations have different effects in the stated Terraform workflow.

C:

The -var-file flag explicitly selects a variables file rather than relying on auto-loaded naming conventions; this mechanism is useful when the job is to load a nonstandard variable file selected for one environment, whereas the current scenario requires the engineer to ask the caller for a value when no default should be assumed. These operations have different effects in the stated Terraform workflow.

D:

Terraform automatically discovers terraform.tfvars and terraform.tfvars.json in the working directory; this mechanism is useful when the job is to load a conventional set of root-module variable assignments automatically, whereas the current scenario requires the engineer to ask the caller for a value when no default should be assumed. These operations have different effects in the stated Terraform workflow.

Question 188

During an infrastructure design review about how to preview resource actions implied by the current configuration and state, a maintainer asks what “terraform plan” does. Which description is accurate?

  1. The -json flag emits a structured JSON representation suitable for inspection by automation, with careful handling of sensitive output.
  2. Planning calculates an execution proposal after reading configuration and usually refreshing managed resource data.
  3. The graph command emits a DOT graph representation of Terraform dependencies, useful for spotting unexpected ordering constraints.
  4. In conventional human-readable plans, + signifies that a managed resource is proposed for creation.

Explanation

Correct Answer

B:

The named mechanism is used when the objective is to preview resource actions implied by the current configuration and state, so it produces the behavior described. In contrast, a resource action marked plus serves a different goal: interpret the leading + symbol in Terraform's plan, not preview resource actions implied by the current configuration and state.

Incorrect Answers

A:

The description applies to terraform show -json on a plan when an engineer needs to feed a saved plan to a machine-readable analysis tool; the named terraform plan instead handles the requirement to preview resource actions implied by the current configuration and state, so this behavior does not describe terraform plan in the situation named.

C:

The description applies to terraform graph when an engineer needs to display configuration and state dependencies for troubleshooting; the named terraform plan instead handles the requirement to preview resource actions implied by the current configuration and state, so this behavior does not describe terraform plan in the situation named.

D:

The description applies to a resource action marked plus when an engineer needs to interpret the leading + symbol in Terraform's plan; the named terraform plan instead handles the requirement to preview resource actions implied by the current configuration and state, so this behavior does not describe terraform plan in the situation named.

Question 189

A Terraform deployment has independent requirements: (1) suppress Terraform's normal approval prompt in a controlled pipeline; (2) modify and re-plan after a change request is rejected. Which TWO mechanisms directly address these needs? Choose TWO.

  1. Parallel graph execution
  2. Iterate after feedback
  3. Refresh during apply planning
  4. Keep configuration in version control
  5. terraform apply -auto-approve
  6. Apply failure recovery

Explanation

Correct Answers

B:

A revised configuration must be planned again because a prior plan does not automatically incorporate later edits; this meets the requirement to modify and re-plan after a change request is rejected, while the other selected techniques address suppress Terraform's normal approval prompt in a controlled pipeline, which require their own distinct Terraform mechanisms.

E:

The auto-approve option allows the automatically created plan to proceed without interactive confirmation, so pipeline safeguards matter; this meets the requirement to suppress Terraform's normal approval prompt in a controlled pipeline, while the other selected techniques address modify and re-plan after a change request is rejected, which require their own distinct Terraform mechanisms.

Incorrect Answers

A:

Terraform executes actions in graph order and can operate on independent nodes in parallel subject to provider and CLI limits; it addresses allow independent resources to be applied concurrently, but this delivery instead requires suppress Terraform's normal approval prompt in a controlled pipeline and modify and re-plan after a change request is rejected. The required combination involves Iterate after feedback and terraform apply -auto-approve, not the behavior of Parallel graph execution.

C:

For a normal fresh apply, Terraform plans with current provider observations unless refresh is explicitly disabled; saved plan behavior differs; it addresses avoid applying from stale remembered attributes after remote drift, but this delivery instead requires suppress Terraform's normal approval prompt in a controlled pipeline and modify and re-plan after a change request is rejected. The required combination involves Iterate after feedback and terraform apply -auto-approve, not the behavior of Refresh during apply planning.

D:

Committing root module files allows the team to relate plans and runs to a specific version of intended infrastructure; it addresses tie an approved infrastructure change to a reviewed commit, but this delivery instead requires suppress Terraform's normal approval prompt in a controlled pipeline and modify and re-plan after a change request is rejected. The required combination involves Iterate after feedback and terraform apply -auto-approve, not the behavior of Keep configuration in version control.

F:

A partial apply may have changed some resources, so Terraform should refresh and build a new plan rather than blindly assuming a full rollback; it addresses inspect state and re-plan when a provider operation fails partway through, but this delivery instead requires suppress Terraform's normal approval prompt in a controlled pipeline and modify and re-plan after a change request is rejected. The required combination involves Iterate after feedback and terraform apply -auto-approve, not the behavior of Apply failure recovery.

Question 190

An engineer troubleshooting a .tf configuration has a concrete implementation goal: retrieve an operational credential from a dedicated secret manager rather than committing it. What is the most appropriate Terraform mechanism?

  1. Vault-backed secret retrieval
  2. No ephemeral root output
  3. An ephemeral child module output
  4. No secrets in version control

Explanation

Correct Answer

A:

Vault can centralize secret lifecycle, policies and auditability, but provider and state-handling choices still determine whether a retrieved value is persisted; this directly meets the requirement to retrieve an operational credential from a dedicated secret manager rather than committing it. By comparison, no secrets in version control is intended to keep API keys out of committed terraform.tfvars and .tf files, which is a different task from retrieve an operational credential from a dedicated secret manager rather than committing it.

Incorrect Answers

B:

Terraform does not permit ephemeral = true on root-module output blocks, because their ordinary purpose is persistent presentation; this mechanism is useful when the job is to reject a design that tries to publish a runtime-only value through the root output table, whereas the current scenario requires the engineer to retrieve an operational credential from a dedicated secret manager rather than committing it. These operations have different effects in the stated Terraform workflow.

C:

Ephemeral outputs are permitted on child modules, allowing a value to travel through an allowed ephemeral context without entering state; this mechanism is useful when the job is to pass a temporary sensitive value from a child module to its parent, whereas the current scenario requires the engineer to retrieve an operational credential from a dedicated secret manager rather than committing it. These operations have different effects in the stated Terraform workflow.

D:

Secrets inserted directly into tracked configuration can leak through repository history, regardless of later state redaction; this mechanism is useful when the job is to keep API keys out of committed terraform.tfvars and .tf files, whereas the current scenario requires the engineer to retrieve an operational credential from a dedicated secret manager rather than committing it. These operations have different effects in the stated Terraform workflow.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests