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

Question 200

A pipeline responsible for the Terraform workflow requires a way to catch a resource block lacking a mandatory argument. Which Terraform approach most directly fulfills that request?

  1. terraform test
  2. Variable validation during planning
  3. terraform fmt -check
  4. Validate after init
  5. Validate without live deployment
  6. Missing required argument detection

Explanation

Correct Answer

F:

Validation compares configuration with provider schemas and reports missing required fields; this directly meets the requirement to catch a resource block lacking a mandatory argument. By comparison, validate after init is intended to resolve missing provider schemas before checking configuration, which is a different task from catch a resource block lacking a mandatory argument.

Incorrect Answers

A:

The Terraform test command executes defined test runs and assertions, which can exercise behavior beyond basic configuration validation; this mechanism is useful when the job is to run declarative module tests instead of only checking syntax, whereas the current scenario requires the engineer to catch a resource block lacking a mandatory argument. These operations have different effects in the stated Terraform workflow.

B:

Variable validation conditions evaluate against actual values when Terraform processes inputs, which is different from only checking syntax; this mechanism is useful when the job is to reject a supplied input value that violates a custom validation rule, whereas the current scenario requires the engineer to catch a resource block lacking a mandatory argument. These operations have different effects in the stated Terraform workflow.

C:

The fmt -check option exits with a failure status when source files would need formatting changes rather than altering them; this mechanism is useful when the job is to verify formatting without rewriting the files in a CI job, whereas the current scenario requires the engineer to catch a resource block lacking a mandatory argument. These operations have different effects in the stated Terraform workflow.

D:

Because validate consults provider and module definitions, run init first to install referenced dependencies; this mechanism is useful when the job is to resolve missing provider schemas before checking configuration, whereas the current scenario requires the engineer to catch a resource block lacking a mandatory argument. These operations have different effects in the stated Terraform workflow.

E:

terraform validate runs offline-oriented configuration checks and does not deploy managed resources; this mechanism is useful when the job is to detect invalid configuration even when no cloud changes should occur, whereas the current scenario requires the engineer to catch a resource block lacking a mandatory argument. These operations have different effects in the stated Terraform workflow.

Question 201

A change request asks an engineer to read UTF-8 content already present in a local file during evaluation. Which choice best implements the requested behavior?

  1. The format function
  2. The file function
  3. The for expression
  4. The coalescelist function

Explanation

Correct Answer

B:

file reads existing local text; it does not wait for a provisioner to create the file during apply; this directly meets the requirement to read UTF-8 content already present in a local file during evaluation. By comparison, the for expression is intended to transform a collection's elements into a new list or map, which is a different task from read UTF-8 content already present in a local file during evaluation.

Incorrect Answers

A:

format interpolates arguments into a printf-style string template for predictable names or identifiers; this mechanism is useful when the job is to build formatted text using placeholders for typed values, whereas the current scenario requires the engineer to read UTF-8 content already present in a local file during evaluation. These operations have different effects in the stated Terraform workflow.

C:

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 read UTF-8 content already present in a local file during evaluation. These operations have different effects in the stated Terraform workflow.

D:

coalescelist evaluates list arguments and returns the first with at least one element; this mechanism is useful when the job is to choose the first nonempty list from several candidates, whereas the current scenario requires the engineer to read UTF-8 content already present in a local file during evaluation. These operations have different effects in the stated Terraform workflow.

Question 202

A remote-state operations review requires a way to store Terraform state in a file in the working directory by default. Which Terraform approach most directly fulfills that request?

  1. The default local backend
  2. The terraform.tfstate file
  3. Local state in CI
  4. State file confidentiality

Explanation

Correct Answer

A:

Without another backend, Terraform uses the local backend and writes its default workspace state to terraform.tfstate; this directly meets the requirement to store Terraform state in a file in the working directory by default. By comparison, the terraform.tfstate file is intended to identify Terraform's default local state artifact, which is a different task from store Terraform state in a file in the working directory by default.

Incorrect Answers

B:

The default workspace's local state is kept as terraform.tfstate; this file may contain sensitive infrastructure details; this mechanism is useful when the job is to identify Terraform's default local state artifact, whereas the current scenario requires the engineer to store Terraform state in a file in the working directory by default. These operations have different effects in the stated Terraform workflow.

C:

A temporary runner may lose its filesystem after a job, so durable shared state is usually needed for repeatable team automation; this mechanism is useful when the job is to recognize why ephemeral build agents should not rely on a machine-local state file, whereas the current scenario requires the engineer to store Terraform state in a file in the working directory by default. These operations have different effects in the stated Terraform workflow.

D:

Local state can hold raw provider attributes and secrets, so filesystem access controls and encryption matter; this mechanism is useful when the job is to protect a workstation's local state file even when output values are hidden, whereas the current scenario requires the engineer to store Terraform state in a file in the working directory by default. These operations have different effects in the stated Terraform workflow.

Question 203

During an infrastructure design review about how to enforce read and write privileges on the state object, a maintainer asks what “Remote backend access permissions” does. Which description is accurate?

  1. Cloud storage policy and backend authorization decide who can obtain or mutate stored Terraform state; provider credentials alone are not sufficient.
  2. After changing backend configuration, migrate-state attempts to transfer existing state instead of starting with an empty one.
  3. Supported backends can discover authentication from environment settings or identity mechanisms rather than inline key literals.
  4. Encryption is controlled by the chosen backend service; Terraform's remote backend abstraction does not supply one universal encryption mechanism.

Explanation

Correct Answer

A:

The named mechanism is used when the objective is to enforce read and write privileges on the state object, so it produces the behavior described. In contrast, remote state encryption at rest serves a different goal: protect stored state contents from unauthorized storage-layer access, not enforce read and write privileges on the state object.

Incorrect Answers

B:

The description applies to terraform init -migrate-state when an engineer needs to copy a known working state's snapshot into a new configured backend; the named remote backend access permissions instead handles the requirement to enforce read and write privileges on the state object, so this behavior does not describe Remote backend access permissions in the situation named.

C:

The description applies to backend credentials from the environment when an engineer needs to avoid embedding cloud backend access keys into tracked Terraform source; the named remote backend access permissions instead handles the requirement to enforce read and write privileges on the state object, so this behavior does not describe Remote backend access permissions in the situation named.

D:

The description applies to remote state encryption at rest when an engineer needs to protect stored state contents from unauthorized storage-layer access; the named remote backend access permissions instead handles the requirement to enforce read and write privileges on the state object, so this behavior does not describe Remote backend access permissions in the situation named.

Question 204

During a design review, the requirement is to configure a child module with parent-provided values. Which option should the engineer select?

  1. A root output block
  2. Passing module inputs explicitly
  3. terraform output -raw
  4. A terraform.tfvars file

Explanation

Correct Answer

B:

The module block assigns arguments corresponding to input variables declared in the child; variables are scoped to modules; this directly meets the requirement to configure a child module with parent-provided values. By comparison, terraform output -raw is intended to extract a primitive output without the surrounding formatted representation, which is a different task from configure a child module with parent-provided values.

Incorrect Answers

A:

An output block exposes an expression value to CLI users and supported automation or cross-configuration consumers; this mechanism is useful when the job is to publish a computed result after applying a root module, whereas the current scenario requires the engineer to configure a child module with parent-provided values. These operations have different effects in the stated Terraform workflow.

C:

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 configure a child module with parent-provided values. 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 configure a child module with parent-provided values. These operations have different effects in the stated Terraform workflow.

Question 205

An engineer troubleshooting a .tf configuration has a concrete implementation goal: trigger replacement from a plain variable value change. What is the most appropriate Terraform mechanism?

  1. terraform_data as a replacement trigger
  2. Explicit depends_on for side effects
  3. Dependency cycle resolution
  4. count and depends_on together

Explanation

Correct Answer

A:

A terraform_data resource can expose input-related lifecycle actions for replace_triggered_by, which expects managed resource changes; this directly meets the requirement to trigger replacement from a plain variable value change. By comparison, explicit depends_on for side effects is intended to order a resource after a prerequisite that has no referenced attribute, which is a different task from trigger replacement from a plain variable value change.

Incorrect Answers

B:

The depends_on meta-argument is suitable when a real dependency exists but no normal expression reference conveys it; this mechanism is useful when the job is to order a resource after a prerequisite that has no referenced attribute, whereas the current scenario requires the engineer to trigger replacement from a plain variable value change. These operations have different effects in the stated Terraform workflow.

C:

Dependency cycles cannot be topologically ordered and require restructuring the relationships or splitting responsibilities; this mechanism is useful when the job is to correct a pair of modules that each require the other's output to initialize, whereas the current scenario requires the engineer to trigger replacement from a plain variable value change. These operations have different effects in the stated Terraform workflow.

D:

The depends_on edge can relate the whole counted resource block to an upstream resource, rather than computing one edge by list position; this mechanism is useful when the job is to make multiple resource instances wait for a shared prerequisite, whereas the current scenario requires the engineer to trigger replacement from a plain variable value change. These operations have different effects in the stated Terraform workflow.

Question 206

An engineer intends to serialize a Terraform value into a valid JSON string and is reviewing “The jsonencode function”. What consequence follows from using it as intended?

  1. lookup(map, key, default) retrieves the selected key's value or the supplied default if the key does not exist.
  2. jsonencode converts Terraform values into JSON representation suitable for API fields expecting JSON text.
  3. The condition ? value_a : value_b expression chooses a suitable branch without creating duplicate resource blocks.
  4. sort returns an ordered list of string elements according to lexical comparison rather than original insertion order.

Explanation

Correct Answer

B:

The named mechanism is used when the objective is to serialize a Terraform value into a valid JSON string, so it produces the behavior described. In contrast, the sort function serves a different goal: sort a list of strings lexicographically, not serialize a Terraform value into a valid JSON string.

Incorrect Answers

A:

The description applies to the lookup function when an engineer needs to read a map element and provide a fallback when the key is absent; the named the jsonencode function instead handles the requirement to serialize a Terraform value into a valid JSON string, so this behavior does not describe The jsonencode function in the situation named.

C:

The description applies to the ternary conditional operator when an engineer needs to set a resource argument according to a boolean expression; the named the jsonencode function instead handles the requirement to serialize a Terraform value into a valid JSON string, so this behavior does not describe The jsonencode function in the situation named.

D:

The description applies to the sort function when an engineer needs to sort a list of strings lexicographically; the named the jsonencode function instead handles the requirement to serialize a Terraform value into a valid JSON string, so this behavior does not describe The jsonencode function in the situation named.

Question 207

A release pipeline preparing provider access has a concrete implementation goal: supply provider configurations from the root module to reusable child modules. What is the most appropriate Terraform mechanism?

  1. Provider configuration at the root
  2. A resource's provider meta-argument
  3. A default provider configuration
  4. An aliased provider instance

Explanation

Correct Answer

A:

Reusable child modules should primarily declare provider requirements and receive configurations from callers rather than embedding fixed credentials; this directly meets the requirement to supply provider configurations from the root module to reusable child modules. By comparison, an aliased provider instance is intended to create resources in a second region using the same provider type, which is a different task from supply provider configurations from the root module to reusable child modules.

Incorrect Answers

B:

The resource-level provider meta-argument selects a provider instance, not a different backend or Terraform workspace; this mechanism is useful when the job is to route a particular managed object to the named alternate provider configuration, whereas the current scenario requires the engineer to supply provider configurations from the root module to reusable child modules. 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 supply provider configurations from the root module to reusable child modules. These operations have different effects in the stated Terraform workflow.

D:

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 supply provider configurations from the root module to reusable child modules. These operations have different effects in the stated Terraform workflow.

Question 208

A Terraform module author needs to count elements in a collection or characters in a string. Which feature or operation is the most direct match?

  1. The length function
  2. The cidrsubnet function
  3. The flatten function
  4. The merge function

Explanation

Correct Answer

A:

length returns the collection size or string character count; it does not find an element's index; this directly meets the requirement to count elements in a collection or characters in a string. By comparison, the flatten function is intended to remove nested list layers to obtain a flat sequence, which is a different task from count elements in a collection or characters in a string.

Incorrect Answers

B:

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 count elements in a collection or characters in a string. 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 count elements in a collection or characters in a string. These operations have different effects in the stated Terraform workflow.

D:

merge overlays object or map arguments and chooses the value from the last argument containing a duplicate key; this mechanism is useful when the job is to combine maps with later values overriding earlier keys, whereas the current scenario requires the engineer to count elements in a collection or characters in a string. These operations have different effects in the stated Terraform workflow.

Question 209

A Terraform change proposal names “An aliased provider instance” to create resources in a second region using the same provider type. Which outcome can reviewers attribute to that particular mechanism?

  1. The required_providers entry maps the chosen local name to a specific fully qualified provider source address.
  2. The module call's providers argument maps the child's expected provider configuration name to a provider configuration available in the parent.
  3. The resource-level provider meta-argument selects a provider instance, not a different backend or Terraform workspace.
  4. Declare an aliased provider configuration and assign provider = provider_name.alias on resources that need the alternate region.

Explanation

Correct Answer

D:

The named mechanism is used when the objective is to create resources in a second region using the same provider type, so it produces the behavior described. In contrast, the providers map on a module call serves a different goal: pass an aliased provider configuration into a child module, not create resources in a second region using the same provider type.

Incorrect Answers

A:

The description applies to provider-local name mapping when an engineer needs to reuse a provider whose source address differs from its short local identifier; the named an aliased provider instance instead handles the requirement to create resources in a second region using the same provider type, so this behavior does not describe An aliased provider instance in the situation named.

B:

The description applies to the providers map on a module call when an engineer needs to pass an aliased provider configuration into a child module; the named an aliased provider instance instead handles the requirement to create resources in a second region using the same provider type, so this behavior does not describe An aliased provider instance in the situation named.

C:

The description applies to a resource's provider meta-argument when an engineer needs to route a particular managed object to the named alternate provider configuration; the named an aliased provider instance instead handles the requirement to create resources in a second region using the same provider type, so this behavior does not describe An aliased provider instance in the situation named.

Question 210

An operations handover for an existing Terraform deployment has a concrete implementation goal: check that Terraform configuration is structurally valid without planning resource changes. What is the most appropriate Terraform mechanism?

  1. terraform validate
  2. A type mismatch diagnosis
  3. terraform fmt -check
  4. terraform test

Explanation

Correct Answer

A:

The validate command checks syntax and schema consistency in an initialized configuration without obtaining a full execution plan; this directly meets the requirement to check that Terraform configuration is structurally valid without planning resource changes. By comparison, a type mismatch diagnosis is intended to catch an argument whose expression does not match the provider schema, which is a different task from check that Terraform configuration is structurally valid without planning resource changes.

Incorrect Answers

B:

Provider schemas and Terraform's type checking can make validate fail before an apply is attempted; this mechanism is useful when the job is to catch an argument whose expression does not match the provider schema, whereas the current scenario requires the engineer to check that Terraform configuration is structurally valid without planning resource changes. These operations have different effects in the stated Terraform workflow.

C:

The fmt -check option exits with a failure status when source files would need formatting changes rather than altering them; this mechanism is useful when the job is to verify formatting without rewriting the files in a CI job, whereas the current scenario requires the engineer to check that Terraform configuration is structurally valid without planning resource changes. These operations have different effects in the stated Terraform workflow.

D:

The Terraform test command executes defined test runs and assertions, which can exercise behavior beyond basic configuration validation; this mechanism is useful when the job is to run declarative module tests instead of only checking syntax, whereas the current scenario requires the engineer to check that Terraform configuration is structurally valid without planning resource changes. These operations have different effects in the stated Terraform workflow.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests