Which Terraform variable type is best suited to capture configuration values that include a memory field as a number and a server name as a string?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

Which Terraform variable type is best suited to capture configuration values that include a memory field as a number and a server name as a string?

Explanation:
Capturing a memory value (number) and a server name (string) together requires a structured, typed payload with named fields. The object type in Terraform lets you define exactly that: named attributes, each with its own type. For example, you can declare a variable as an object with memory as a number and server_name as a string, then provide values like memory = 4096 and server_name = "web-01" and access them as config.memory and config.server_name. Lists group items by position and don’t express different meanings for each element, so they’re not ideal for heterogenous data. Maps store values under keys but all values share a single type, so mixing a number and a string in one map is either awkward or loses type safety. Terraform does support complex inputs, but the object type is the cleanest, most type-safe way to model a configuration with distinct fields.

Capturing a memory value (number) and a server name (string) together requires a structured, typed payload with named fields. The object type in Terraform lets you define exactly that: named attributes, each with its own type. For example, you can declare a variable as an object with memory as a number and server_name as a string, then provide values like memory = 4096 and server_name = "web-01" and access them as config.memory and config.server_name.

Lists group items by position and don’t express different meanings for each element, so they’re not ideal for heterogenous data. Maps store values under keys but all values share a single type, so mixing a number and a string in one map is either awkward or loses type safety. Terraform does support complex inputs, but the object type is the cleanest, most type-safe way to model a configuration with distinct fields.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy