Courseiva

CCNA Dynamic Hcl Configuration Questions

29 questions · Dynamic Hcl Configuration topic · All types, answers revealed

1
MCQhard

What happens if you use a dynamic block with a 'for_each' expression that evaluates to an empty set?

A.It pauses execution and waits for input
B.It throws a configuration error
C.It renders no blocks
D.It generates a single block with null values
AnswerC

An empty list or set results in no dynamic blocks being created.

Why this answer

If the collection for a dynamic block is empty, the block is not rendered at all in the resulting resource configuration.

2
MCQhard

You are writing a module that accepts a list of objects. You want to validate that the 'port' attribute in each object is a number. How can you enforce this?

A.Use the type constraint
B.Use a local variable
C.Use a validation block
D.Use the any type
AnswerA, C

Strictly speaking, type constraints in the variable block are the foundation.

Why this answer

Using the 'type' constraint with an 'object' or 'list(object)' definition allows you to specify the expected type of every attribute.

3
MCQmedium

In a dynamic block, you need to access the current iteration item. What is the default label assigned to the iterator object?

A.count.index
B.The name of the block
C.each.value
D.item
AnswerB

The iterator automatically takes the name of the dynamic block defined.

Why this answer

By default, the iterator name is the same as the name of the dynamic block, unless an 'iterator' argument is explicitly provided.

4
MCQeasy

You want to optionally create an S3 bucket only if a specific variable 'create_bucket' is set to true. Which HCL feature is best for this?

A.conditional expression (ternary)
B.try()
C.dynamic block
D.for_each
AnswerA

Setting count = var.enabled ? 1 : 0 is the common pattern for optional resource creation.

Why this answer

Conditional expressions using the ternary operator are the standard way to conditionally enable or disable resources by setting count to 0 or 1.

5
Multi-Selectmedium

Which TWO of the following are valid uses of the 'for' expression?

Select 2 answers
A.Defining a resource
B.Generating a list
C.Managing provider blocks
D.Creating dynamic blocks
E.Generating a map
AnswersB, E

Using [] syntax.

Why this answer

for expressions can be used to generate lists (using brackets) or maps (using braces).

6
Multi-Selectmedium

Which THREE of the following are valid ways to transform data for Terraform configuration?

Select 3 answers
A.flatten()
B.merge()
C.split_map()
D.loop()
E.for expressions
AnswersA, B, E

Utility function for list transformation.

Why this answer

for expressions, the flatten() function, and the merge() function are standard ways to manipulate data.

7
Multi-Selecteasy

Which TWO of the following are valid meta-arguments for managing resource instances?

Select 2 answers
A.dynamic
B.lifecycle
C.count
D.depends_on
E.for_each
AnswersC, E

A core meta-argument for resource instances.

Why this answer

count and for_each are the two primary meta-arguments in Terraform for creating multiple resource instances.

8
Multi-Selecteasy

Which TWO of the following functions are most useful for manipulating lists?

Select 2 answers
A.keys()
B.concat()
C.flatten()
D.lookup()
E.merge()
AnswersB, C

Used for joining lists.

Why this answer

flatten() and concat() are essential for managing list structures.

9
Multi-Selecthard

Which THREE of the following represent potential pitfalls when using 'count'?

Select 3 answers
A.Inability to use string keys for identification
B.Complex logic for conditional creation
C.Index shifts when removing list items
D.Performance issues with large collections
E.Type mismatch errors
AnswersA, B, C

Forces integer index management.

Why this answer

Issues include index shifts during item removal, inability to use map keys for identification, and rigid structure for varying configurations.

10
Multi-Selectmedium

Which THREE of the following are valid HCL collection types?

Select 3 answers
A.queue
B.table
C.set
D.map
E.list
AnswersC, D, E

A core collection type.

Why this answer

list, map, and set are the primary collection types used in HCL.

11
MCQmedium

Which of these is a valid use case for a dynamic block?

A.Defining nested repeatable blocks
B.Conditional module inclusion
C.Changing the provider configuration dynamically
D.Defining multiple separate resources
AnswerA

Dynamic blocks are designed for nested, repeatable configuration blocks.

Why this answer

Dynamic blocks are specifically intended to generate nested, repeatable blocks within a resource, such as 'ingress' rules in a security group or 'tags' in an instance.

12
Multi-Selecthard

Which TWO of the following statements are correct regarding 'for_each' and state?

Select 2 answers
A.for_each creates stable identifiers based on keys
B.count is preferred for all resource types
C.count creates stable identifiers based on keys
D.for_each is preferred over count for map-based configurations
E.for_each is only available for cloud resources
AnswersA, D

Using keys makes resource identity stable.

Why this answer

for_each uses keys which provides stable identities, whereas count uses indices which can cause resource drift if lists change.

13
MCQeasy

Which meta-argument is best for deploying resources that are strictly dependent on the number of items in a configuration?

A.count
B.for_each
C.provider
D.dynamic
AnswerA

count is the primary meta-argument for simple integer-based replication.

Why this answer

count is the simplest meta-argument for simple, index-based resource replication where individual resource identity is not critical.

14
Multi-Selecthard

Which TWO of the following are requirements when using a 'dynamic' block?

Select 2 answers
A.A content block
B.A count argument
C.A for_each argument
D.A provider argument
E.An iterator argument
AnswersA, C

Required to define the content of the generated block.

Why this answer

A dynamic block requires a 'for_each' argument to define the iteration, and a 'content' block to define the nested structure.

15
MCQmedium

When using for_each on a resource, how do you access the value of the current iteration inside the resource configuration?

A.each.value
B.each.key
C.item.value
D.count.index
AnswerA

each.value provides the current element from the map or set.

Why this answer

The 'each.value' object is the standard way to access the value in the collection currently being processed by for_each.

16
MCQeasy

You are creating a security group in AWS and need to define multiple ingress rules based on a list of port numbers. Which meta-argument is most appropriate to use to create one resource instance per port?

A.instance_count
B.count
C.dynamic
D.for_each
AnswerD

for_each is the standard approach for creating multiple resource instances from a collection of values.

Why this answer

The count meta-argument creates multiple instances based on an integer, while for_each is designed for sets or maps, making it the idiomatic choice for collections like lists of port numbers.

17
MCQmedium

You are iterating over a map using for_each. You need to access the key of the current map element. Which object do you use?

A.var.key
B.each.key
C.count.key
D.each.value
AnswerB

each.key is the correct reference for the map index.

Why this answer

each.key provides the key of the map entry currently being processed during a for_each iteration.

18
MCQmedium

How can you debug the output of a complex 'for' expression in Terraform?

A.Check the state file
B.Use terraform plan
C.Use terraform console
D.Use terraform debug
AnswerC

terraform console provides an interactive REPL for testing HCL.

Why this answer

The 'terraform console' command is the standard way to interactively evaluate HCL expressions and debug complex transformations.

19
MCQeasy

When using 'for_each' on a list of strings, what must you do to ensure the configuration is stable?

A.Use count instead
B.Convert the list to a set
C.Use the index
D.Nothing, it's always stable
AnswerB

Converting to a set provides stable keys based on the value content.

Why this answer

Using a list directly with for_each is often unstable if the list order changes. Converting it to a set with toset() ensures each item has a stable key.

20
MCQeasy

Which function is most useful when you have a nested list of objects and want to create a single flat list to iterate over with for_each?

A.concat()
B.flatten()
C.lookup()
D.merge()
AnswerB

flatten simplifies nested list structures into a single list.

Why this answer

The flatten() function is specifically designed to take nested lists and turn them into a single-level list.

21
MCQhard

In HCL, how do you handle a scenario where a variable might be null but you need to provide a non-null default value for a resource argument?

A.using try()
B.using count
C.using coalesce()
D.using for_each
AnswerC

coalesce() returns the first non-null argument, making it perfect for defaults.

Why this answer

The coalesce() function is ideal for providing a fallback value if the primary input is null.

22
MCQeasy

Which function allows you to safely access a map value even if the key might not exist?

A.try()
B.element()
C.lookup()
D.coalesce()
AnswerC

lookup() is designed to provide a default if a key is missing.

Why this answer

The lookup() function allows you to provide a default value to return if the requested key is not found in the map.

23
MCQhard

You are attempting to use a conditional expression to set a variable, but the types returned by the true and false results differ. What happens?

A.The result is coerced to a string
B.A type mismatch error is returned
C.It defaults to the true result type
D.Terraform automatically casts to the most flexible type
AnswerB

Terraform demands that both expressions return the same type.

Why this answer

Terraform requires that both branches of a conditional expression return the same type, otherwise it will throw a type mismatch error during the planning phase.

24
MCQeasy

What is the primary difference between 'count' and 'for_each' regarding state management?

A.for_each is only for maps
B.for_each does not support complex objects
C.count is faster than for_each
D.count uses index-based indexing, causing potential recreation when items are removed
AnswerD

Because count uses integer indices, changing the list order or removing items causes index shifts.

Why this answer

count depends on list order, so removing an item from the middle of the list causes all subsequent resources to be recreated. for_each uses keys, which are stable.

25
MCQhard

You want to pass a complex object type to a module, but you need to ensure specific attributes are present. How do you define this in the variable block?

A.type = map(any)
B.type = list(object)
C.type = object({...})
D.type = tuple([...])
AnswerC

The object type constraint enforces both the presence and the type of specific attributes.

Why this answer

The 'object' type constraint allows you to define a schema with specific attributes and their corresponding types.

26
MCQmedium

You have a list of strings that you want to convert into a set to use with for_each. Which function is preferred?

A.toset()
B.tomap()
C.distinct()
D.distinct()
E.tolist()
AnswerA

toset converts a list to a set, ideal for stable iteration.

Why this answer

The toset() function is the correct way to convert a list of strings into a set, which is required for for_each to avoid index-based instability.

27
Multi-Selectmedium

Which THREE of the following are valid ways to pass data to a module dynamically?

Select 3 answers
A.Using variables
B.Directly editing the state
C.Using a dynamic block for module calling
D.Using for_each on a module block
E.Using complex object types
AnswersA, D, E

Standard approach.

Why this answer

Passing variables, using for_each in the module block (if supported), or local variable composition are standard.

28
MCQhard

You are using a dynamic block to define multiple 'tag' blocks inside an AWS resource. The dynamic block is failing because it expects a set of objects but receives a flat list. Which function best prepares your data?

A.keys()
B.distinct()
C.compact()
D.toset()
AnswerD

toset converts a list to a set, which is the preferred input for for_each to maintain stable resource indices.

Why this answer

The toset() function converts a list of strings or objects into a set, which is required by for_each to avoid index-based dependencies.

29
MCQmedium

You have a list of objects representing AWS tags. You need to transform this list into a map for use with a for_each argument. Which function should you use?

A.tolist()
B.flatten()
C.merge()
D.for expression
AnswerD

The for expression is the standard HCL construct for transforming lists into maps for resource iteration.

Why this answer

The for expression is the primary tool for transforming collections, allowing you to iterate over a list and produce a map.

Ready to test yourself?

Try a timed practice session using only Dynamic Hcl Configuration questions.