You must read and write HCL that passes typed objects to modules, validates inputs with condition and error_message, transforms collections with for expressions, and generates nested blocks dynamically. The critical skill is matching type constraints and validation conditions to the actual data shape.
Start practicing
Dynamic HCL Configuration — choose a session length
Free · No account required
Domain overview
Dynamic HCL Configuration covers expressions, variables, validation, and dynamic blocks in Terraform. Questions present real HCL snippets and ask you to choose correct syntax, predict plan/apply behavior, or fix errors. You must reason about type constraints, for expressions, validation rules, and nested dynamic blocks using the AWS provider.
Exam objectives
Defining complex object type constraints in variable blocks with optional() and required attributes
Using for expressions to transform lists, maps, and sets into new collections
Writing variable validation blocks with condition and error_message to reject invalid plans
Building dynamic blocks that generate aws_security_group ingress rules from list objects
Confusing for expressions with for_each meta-argument, producing invalid syntax or wrong iteration behavior
Omitting optional() in object type constraints, causing errors when callers pass partial objects
Placing validation in the wrong block or using a condition that references unavailable values at plan time
Click any question to see the full explanation and answer options, or start a focused practice session above.
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?
2You 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?
3In a dynamic block, you need to access the current iteration item. What is the default label assigned to the iterator object?
4When using for_each on a resource, how do you access the value of the current iteration inside the resource configuration?
5Which 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?
6You 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?
7You 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?
8What is the primary difference between 'count' and 'for_each' regarding state management?
9What happens if you use a dynamic block with a 'for_each' expression that evaluates to an empty set?
10You are iterating over a map using for_each. You need to access the key of the current map element. Which object do you use?
11You 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?
12Which function allows you to safely access a map value even if the key might not exist?
13When using 'for_each' on a list of strings, what must you do to ensure the configuration is stable?
14Which of these is a valid use case for a dynamic block?
15Which meta-argument is best for deploying resources that are strictly dependent on the number of items in a configuration?
16How can you debug the output of a complex 'for' expression in Terraform?
17Which TWO of the following are valid uses of the 'for' expression?
18Which TWO of the following statements are correct regarding 'for_each' and state?
19Which THREE of the following are valid ways to transform data for Terraform configuration?
20Which TWO of the following functions are most useful for manipulating lists?
21Which THREE of the following represent potential pitfalls when using 'count'?
22Which THREE of the following are valid ways to pass data to a module dynamically?
23You are authoring a Terraform configuration that provisions an aws_autoscaling_group. The desired instance count is stored in a variable named instance_count, and you need to create exactly that many aws_instance resources. Which approach correctly creates the required number of instances while keeping the configuration valid?
24Your team manages AWS infrastructure with Terraform. A module needs to accept a map of environment names to instance types, where each instance type must be one of a fixed set of allowed values. You want Terraform to reject invalid configurations during plan with a clear error message. Which approach best validates the variable input?
25You are writing a Terraform configuration that reads a list of environment names from a variable and creates one aws_s3_bucket for each environment. The order of the list may change over time, and you want to avoid unnecessary bucket replacement. Which configuration snippet achieves this with stable resource addressing?
26You are authoring a Terraform module that creates an AWS IAM policy. The policy's Statement blocks must be generated from a list of objects, but each Statement must also conditionally include a Condition block only when the object's condition attribute is non-null. Which approach correctly generates the Statement blocks while conditionally including the nested Condition block?
27You maintain a Terraform module that deploys AWS resources into several environments. Rather than declaring a separate variable per environment, you want a single input variable that accepts a map of environment names to configuration objects, where each object contains a region string and an instance count number, and your configuration should reject any input that does not match this shape at plan time. Which variable type constraint should you declare?
28You are authoring a Terraform module that must accept a map of environment names to instance counts. The map is provided by callers and may contain up to 20 entries. You need to derive a flat list of instance names in the form "<env>-<index>" (e.g., "prod-0", "prod-1") so that a downstream resource can use `for_each` with stable keys. Which expression correctly produces this list?
29You are writing a Terraform configuration that creates multiple AWS S3 buckets. The bucket names are derived from a list of project names, but you need to ensure that the names are unique and that the configuration can be safely modified without affecting existing buckets. Which approach should you use?
30You are writing a Terraform configuration that uses a dynamic block to generate multiple ingress rules within an aws_security_group resource. The dynamic block iterates over a variable named ingress_rules. Inside the content block, you need to reference the current rule. Which expression correctly accesses the current element?
31A configuration defines a dynamic block that generates ingress rules for an aws_security_group from a list of objects. Each object has a from_port, to_port, and protocol attribute, and one object also carries an extra cidr_blocks list. You want every generated rule to include the from_port, to_port, and protocol values, and to include cidr_blocks only when it is present, without writing a separate block for the odd entry. Which approach satisfies this?
32You are writing a Terraform configuration that uses a for expression to transform a map of objects into a new map. The original map has keys that are strings, and each object contains an attribute 'enabled' of type bool. You need to create a new map that includes only the entries where 'enabled' is true, and the new map's keys should be the original keys prefixed with 'prod-'. Which for expression achieves this?
33You have a Terraform variable defined as a list of objects, each with a name and a list of ports. You need to create AWS security group rules for each port across all objects. Which expression correctly generates a flattened list of objects containing the name and port for each combination?
34You are defining an input variable for a Terraform module that will accept a map of environment names to configuration objects. The object should have an instance_type string and a min_size number. You want Terraform to validate that any provided value matches this structure. Which type constraint should you use for the variable?
35A team defines an aws_instance resource whose instance_type should normally come from a variable, but for one specific workspace named "dr" the value must be forced to t3.micro regardless of the variable. The team wants a single resource block that behaves correctly in every workspace without duplicating the resource. Which expression assigns instance_type appropriately?
36An engineer is authoring a reusable module that accepts variable "subnets", typed as map(object({ cidr_block = string, public = bool })). The module must create one aws_subnet per entry, attaching an aws_route_table_association only when that entry's public attribute is true. The association resource must not appear at all for private subnets, and its key must match the subnet's map key. Which approach satisfies these requirements with the least waste?
37You are writing a Terraform configuration that uses a `dynamic` block to generate multiple `ingress` blocks inside an `aws_security_group` resource. The `var.ingress_rules` variable is a list of objects with `from_port`, `to_port`, and `cidr_blocks`. You need to reference the current rule inside the dynamic block's content. Which iterator configuration and reference is correct?
38You are defining an input variable for a Terraform module that will accept a list of AWS subnet IDs. You want to ensure that the variable only accepts a list of strings and that it is required. Which variable declaration correctly achieves this?
39You are writing a Terraform configuration that uses a conditional expression to set the instance type for an AWS EC2 instance. The condition checks if the environment is production. The true branch returns a string, but the false branch returns a number. What will happen when you run terraform plan?
40You are using a for expression to create a map from a list of objects. Each object has an attribute 'name' that is a string. You want the resulting map's keys to be the 'name' values and the values to be the entire objects. However, you encounter an error because some objects have duplicate 'name' values. How can you modify the for expression to handle duplicates by grouping objects with the same name into a list, so that the map values become lists of objects?
41A team wants to pass a variable "allowed_ports" to a module and guarantee at apply time that every value is an integer between 1024 and 65535, rejecting invalid plans with a clear message. They prefer the validation to live in the variable block so callers get immediate feedback. Which declaration accomplishes this?
42A module needs to render a JSON policy document where the list of allowed actions comes from a variable that may contain duplicates and mixed case, and the final output must be deterministic and free of duplicates. The engineer writes jsonencode({ Version = "2012-10-17", Statement = [{ Effect = "Allow", Action = local.actions, Resource = "*" }] }). Which local definition for local.actions best guarantees determinism and uniqueness?
43A team defines a variable `allowed_ports` as `list(number)` and wants to validate that every value is between 1 and 65535 before any resources are planned. They add a `validation` block to the variable. Which configuration correctly enforces this constraint?
44You are writing a Terraform configuration that uses a `for` expression to transform a list of strings into a map where each string is both the key and the value. Which of the following expressions achieves this?
You must read and write HCL that passes typed objects to modules, validates inputs with condition and error_message, transforms collections with for expressions, and generates nested blocks dynamically. The critical skill is matching type constraints and validation conditions to the actual data shape.
The Courseiva AWS provider question bank contains 44 questions in the Dynamic HCL Configuration domain. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Dynamic HCL Configuration domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included