HashiCorp Terraform Associate 004 (HashiCorp Certified: Terraform Associate (004)) Practice Test 120

Question 1190

A Terraform 1.12 configuration evaluates slice([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 1, 2). Which result follows from the expression as written?

  1. ["ALPHA"]
  2. []
  3. ["GAMMA"]
  4. ["ALPHA", "GAMMA"]

Explanation

Correct Answer

C:

For the specific expression slice([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 1, 2), First, the if filter discards beta before transforming the longer values to uppercase; slice begins at zero-based index one and continues through the final member, stopping before the exclusive end index 2.

Incorrect Answers

A:

For the concrete expression slice([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 1, 2), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["ALPHA", "GAMMA"] before the outer operation is applied.

B:

For the concrete expression slice([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 1, 2), the final end index is exclusive, but the last element still lies before that boundary; the inner stage produces ["ALPHA", "GAMMA"] before the outer operation is applied.

D:

For the concrete expression slice([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 1, 2), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["ALPHA", "GAMMA"] before the outer operation is applied.

Question 1191

A Terraform 1.12 configuration evaluates format("primary=%s", element([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 0)). Which result follows from the expression as written?

  1. "primary=GAMMA"
  2. "ALPHA"
  3. "secondary=ALPHA"
  4. "primary=ALPHA"

Explanation

Correct Answer

D:

For the specific expression format("primary=%s", element([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 0)), First, the if filter discards beta before transforming the longer values to uppercase; element at zero selects the first member, and the single %s placeholder in format substitutes that member after the literal primary= prefix.

Incorrect Answers

A:

For the concrete expression format("primary=%s", element([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["ALPHA", "GAMMA"] before the outer operation is applied.

B:

For the concrete expression format("primary=%s", element([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["ALPHA", "GAMMA"] before the outer operation is applied.

C:

For the concrete expression format("primary=%s", element([for s in ["alpha", "beta", "gamma"] : upper(s) if length(s) > 4], 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["ALPHA", "GAMMA"] before the outer operation is applied.

Question 1192

A Terraform 1.12 configuration evaluates length(reverse(split(".", "db.prod.internal"))). Which result follows from the expression as written?

  1. 3
  2. 0
  3. 4
  4. 6

Explanation

Correct Answer

A:

For the specific expression length(reverse(split(".", "db.prod.internal"))), First, split forms three DNS labels and reverse puts them in reverse sequence; that produces exactly 3 elements; The outer length call counts those resulting elements rather than the original textual arguments.

Incorrect Answers

B:

For the concrete expression length(reverse(split(".", "db.prod.internal"))), the inner expression is not empty: it produces 3 elements; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

C:

In the calculation length(reverse(split(".", "db.prod.internal"))), 4 is not the size of the evaluated collection: the inner result has 3 elements, and length counts precisely those elements.

D:

For the concrete expression length(reverse(split(".", "db.prod.internal"))), no stage of the expression creates 6 list elements; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

Question 1193

A Terraform 1.12 configuration evaluates join("/", reverse(split(".", "db.prod.internal"))). Which result follows from the expression as written?

  1. "internal/prod/db/db"
  2. "internal/prod/db"
  3. "internalproddb"
  4. "db/prod/internal"

Explanation

Correct Answer

B:

For the specific expression join("/", reverse(split(".", "db.prod.internal"))), First, split forms three DNS labels and reverse puts them in reverse sequence; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

A:

For the concrete expression join("/", reverse(split(".", "db.prod.internal"))), join must not repeat the last item after the list has been joined; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

C:

For the concrete expression join("/", reverse(split(".", "db.prod.internal"))), this omits the slash delimiters requested by join; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

D:

For the concrete expression join("/", reverse(split(".", "db.prod.internal"))), this reverses the members even though join preserves the order returned by the inner expression; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

Question 1194

An engineer tests the cidrhost behavior in terraform console. What is the result of cidrhost("10.2.5.0/24", 10)?

  1. "10.2.5.0"
  2. "10.2.5.10"
  3. "10.2.5.24"
  4. "10.2.10.5"

Explanation

Correct Answer

B:

Evaluating the actual call cidrhost("10.2.5.0/24", 10): In the 10.2.5.0/24 network, the address at host offset ten is 10.2.5.10; cidrhost returns that IP string.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression cidrhost("10.2.5.0/24", 10), the network address is host offset zero, not offset ten.

C:

Given the specific operands supplied to the Terraform expression cidrhost("10.2.5.0/24", 10), the prefix length /24 is not the requested host offset.

D:

Given the specific operands supplied to the Terraform expression cidrhost("10.2.5.0/24", 10), the third octet identifies the subnet here; the last octet changes to ten.

Question 1195

A Terraform 1.12 configuration evaluates reverse(reverse(split(".", "db.prod.internal"))). Which result follows from the expression as written?

  1. ["internal", "prod", "db"]
  2. ["db", "internal", "prod"]
  3. ["prod", "db", "internal"]
  4. ["db", "prod", "internal"]

Explanation

Correct Answer

D:

For the specific expression reverse(reverse(split(".", "db.prod.internal"))), First, split forms three DNS labels and reverse puts them in reverse sequence; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

For the concrete expression reverse(reverse(split(".", "db.prod.internal"))), this leaves the inner result unchanged and skips the outer reverse call; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

B:

For the concrete expression reverse(reverse(split(".", "db.prod.internal"))), alphabetic sorting is not the same as reversing the sequence produced by the inner expression; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

C:

For the concrete expression reverse(reverse(split(".", "db.prod.internal"))), rotating the input left one position does not invert every position as reverse requires; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

Question 1196

For Terraform string processing with replace every matching token, evaluate replace("qa-env-qa", "qa", "prod"). Which output is correct?

  1. "prod-env-prod"
  2. "qa-env-qa"
  3. "qa-env-prod"
  4. "prod-env-qa"

Explanation

Correct Answer

A:

Evaluating the actual call replace("qa-env-qa", "qa", "prod"): replace substitutes both occurrences of the qa token with prod, leaving the middle hyphenated env unchanged.

Incorrect Answers

B:

Given the specific operands supplied to the Terraform expression replace("qa-env-qa", "qa", "prod"), both matching qa tokens should change, so the unchanged string is not correct.

C:

Given the specific operands supplied to the Terraform expression replace("qa-env-qa", "qa", "prod"), the qa token also occurs at the front and must be replaced there.

D:

Given the specific operands supplied to the Terraform expression replace("qa-env-qa", "qa", "prod"), the qa token also occurs at the end and must be replaced there.

Question 1197

A Terraform 1.12 configuration evaluates sort(reverse(split(".", "db.prod.internal"))). Which result follows from the expression as written?

  1. ["prod", "internal", "db"]
  2. ["db", "internal", "prod"]
  3. ["db", "prod", "internal"]
  4. ["internal", "prod", "db"]

Explanation

Correct Answer

B:

For the specific expression sort(reverse(split(".", "db.prod.internal"))), First, split forms three DNS labels and reverse puts them in reverse sequence; Terraform sort then compares the resulting strings lexicographically in ascending order; it neither drops values nor preserves a non-sorted arrangement.

Incorrect Answers

A:

For the concrete expression sort(reverse(split(".", "db.prod.internal"))), this puts strings in descending lexical order rather than ascending order; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

C:

For the concrete expression sort(reverse(split(".", "db.prod.internal"))), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

D:

For the concrete expression sort(reverse(split(".", "db.prod.internal"))), this retains the source order rather than explicitly sorting the result (unless it was already sorted); the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

Question 1198

A Terraform 1.12 configuration evaluates element(reverse(split(".", "db.prod.internal")), 4). Which result follows from the expression as written?

  1. "db"
  2. "index out of range"
  3. "prod"
  4. "internal"

Explanation

Correct Answer

C:

For the specific expression element(reverse(split(".", "db.prod.internal")), 4), First, split forms three DNS labels and reverse puts them in reverse sequence; The list has 3 entries, so element wraps index 4 modulo 3 and selects zero-based position one.

Incorrect Answers

A:

For the concrete expression element(reverse(split(".", "db.prod.internal")), 4), the final list member is not selected; the effective index is one; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

B:

For the concrete expression element(reverse(split(".", "db.prod.internal")), 4), element wraps a positive index instead of failing like ordinary square-bracket indexing; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

D:

For the concrete expression element(reverse(split(".", "db.prod.internal")), 4), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

Question 1199

A Terraform 1.12 configuration evaluates slice(reverse(split(".", "db.prod.internal")), 1, 3). Which result follows from the expression as written?

  1. ["internal", "prod", "db"]
  2. ["internal", "prod"]
  3. ["db", "prod"]
  4. ["prod", "db"]

Explanation

Correct Answer

D:

For the specific expression slice(reverse(split(".", "db.prod.internal")), 1, 3), First, split forms three DNS labels and reverse puts them in reverse sequence; slice begins at zero-based index one and continues through the final member, stopping before the exclusive end index 3.

Incorrect Answers

A:

For the concrete expression slice(reverse(split(".", "db.prod.internal")), 1, 3), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

B:

For the concrete expression slice(reverse(split(".", "db.prod.internal")), 1, 3), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

C:

For the concrete expression slice(reverse(split(".", "db.prod.internal")), 1, 3), slice preserves order rather than reversing the extracted portion; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

Question 1200

A Terraform 1.12 configuration evaluates format("primary=%s", element(reverse(split(".", "db.prod.internal")), 0)). Which result follows from the expression as written?

  1. "primary=internal"
  2. "primary=prod"
  3. "internal"
  4. "secondary=internal"

Explanation

Correct Answer

A:

For the specific expression format("primary=%s", element(reverse(split(".", "db.prod.internal")), 0)), First, split forms three DNS labels and reverse puts them in reverse sequence; element at zero selects the first member, and the single %s placeholder in format substitutes that member after the literal primary= prefix.

Incorrect Answers

B:

For the concrete expression format("primary=%s", element(reverse(split(".", "db.prod.internal")), 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

C:

For the concrete expression format("primary=%s", element(reverse(split(".", "db.prod.internal")), 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

D:

For the concrete expression format("primary=%s", element(reverse(split(".", "db.prod.internal")), 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["internal", "prod", "db"] before the outer operation is applied.

HashiCorp Certified: Terraform Associate (004) (Terraform Associate 004) Practice Tests