BlackFriday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

HashiCorp Exam TA-002-P Topic 6 Question 1 Discussion

Actual exam question for HashiCorp's TA-002-P exam
Question #: 1
Topic #: 6
[All TA-002-P Questions]

True or False: A list(...) contain a number of values of the same type while an object(...) can contain a number of values of different types.

Show Suggested Answer Hide Answer
Suggested Answer: B

Collection Types

A collection type allows multiple values of one other type to be grouped together as a single value. The type of value within a collection is called its element type. All collection types must have an element type, which is provided as the argument to their constructor.

For example, the type list(string) means "list of strings", which is a different type than list(number), a list of numbers. All elements of a collection must always be of the same type.

The three kinds of collection type in the Terraform language are:

* list(...): a sequence of values identified by consecutive whole numbers starting with zero.

The keyword list is a shorthand for list(any), which accepts any element type as long as every element is the same type. This is for compatibility with older configurations; for new code, we recommend using the full form.

* map(...): a collection of values where each is identified by a string label.

The keyword map is a shorthand for map(any), which accepts any element type as long as every element is the same type. This is for compatibility with older configurations; for new code, we recommend using the full form.

* set(...): a collection of unique values that do not have any secondary identifiers or ordering.

https://www.terraform.io/docs/configuration/types.html

Structural Types

A structural type allows multiple values of several distinct types to be grouped together as a single value. Structural types require a schema as an argument, to specify which types are allowed for which elements.

The two kinds of structural type in the Terraform language are:

* object(...): a collection of named attributes that each have their own type.

The schema for object types is { = , = , ... } --- a pair of curly braces containing a comma-separated series of = pairs. Values that match the object type must contain all of the specified keys, and the value for each key must match its specified type. (Values with additional keys can still match an object type, but the extra attributes are discarded during type conversion.)

* tuple(...): a sequence of elements identified by consecutive whole numbers starting with zero, where each element has its own type.

The schema for tuple types is [, , ...] --- a pair of square brackets containing a comma-separated series of types. Values that match the tuple type must have exactly the same number of elements (no

more and no fewer), and the value in each position must match the specified type for that position.

For example: an object type of object({ name=string, age=number }) would match a value like the following:

{

name = "John"

age = 52

}

Also, an object type of object({ id=string, cidr_block=string }) would match the object produced by a reference to an aws_vpc resource, like aws_vpc.example_vpc; although the resource has additional attributes, they would be discarded during type conversion.

Finally, a tuple type of tuple([string, number, bool]) would match a value like the following:

["a", 15, true]

https://www.terraform.io/docs/configuration/types.html


Contribute your Thoughts:

Currently there are no comments in this discussion, be the first to comment!


Save Cancel