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?
- ["ALPHA"]
- []
- ["GAMMA"]
- ["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?
- "primary=GAMMA"
- "ALPHA"
- "secondary=ALPHA"
- "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?
- 3
- 0
- 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?
- "internal/prod/db/db"
- "internal/prod/db"
- "internalproddb"
- "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)?
- "10.2.5.0"
- "10.2.5.10"
- "10.2.5.24"
- "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?
- ["internal", "prod", "db"]
- ["db", "internal", "prod"]
- ["prod", "db", "internal"]
- ["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?
- "prod-env-prod"
- "qa-env-qa"
- "qa-env-prod"
- "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?
- ["prod", "internal", "db"]
- ["db", "internal", "prod"]
- ["db", "prod", "internal"]
- ["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?
- "db"
- "index out of range"
- "prod"
- "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?
- ["internal", "prod", "db"]
- ["internal", "prod"]
- ["db", "prod"]
- ["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?
- "primary=internal"
- "primary=prod"
- "internal"
- "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.