Terraform-Associate-004 practice question 17 of 35

You have a list of numbers that represents the number of free CPU cores on each virtual cluster: numcpus = [ 18, 3, 7, 11, 2 ] What Terraform function could you use to select the largest number from the list?

Full set: 360 questions
Answer options
A: top(numcpus)
B: max(numcpus) Correct answer
C: ceil (numcpus)
D: hight[numcpus]
Correct Answer:
B. max(numcpus)
Explanation

The max function in Terraform is a built-in numeric function designed to find the greatest value from a set of numbers. It can accept multiple number arguments or a single list/set of numbers. When provided with the list [18, 3, 7, 11, 2], max(numcpus) will correctly evaluate the elements and return the largest value, which is 18. This directly addresses the requirement of selecting the largest number from the list.

Why Incorrect

A. top(numcpus) is incorrect because top is not a valid built-in function in the Terraform language.
C. ceil(numcpus) is incorrect as the ceil function rounds a single number up to the nearest integer; it does not operate on a list to find the maximum value.
D. hight[numcpus] is incorrect because hight is not a Terraform function, and the syntax is invalid for a function call.

References

1. HashiCorp. (n.d.). Terraform Language: max Function. Terraform by HashiCorp. Retrieved from https://developer.hashicorp.com/terraform/language/functions/max

Section: max Function Documentation. This page explicitly states, "max takes one or more numbers and returns the greatest number from the set." It also shows an example of its usage with a list: > max([5, 12, 9]).

2. HashiCorp. (n.d.). Terraform Language: ceil Function. Terraform by HashiCorp. Retrieved from https://developer.hashicorp.com/terraform/language/functions/ceil

Section: ceil Function Documentation. This page defines ceil as a function that "returns the closest integer that is greater than or equal to the given value," confirming it operates on a single number for rounding, not on a list for comparison.

3. HashiCorp. (n.d.). Terraform Language: Functions. Terraform by HashiCorp. Retrieved from https://developer.hashicorp.com/terraform/language/functions

Section: All Functions. A review of the complete list of built-in functions confirms that top and hight are not valid Terraform functions.

Scroll to Top