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?
When defining a variable with a complex type, which keyword allows you to define a flexible schema where keys are strings and values are a specific type?
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?
You are defining an input variable for a module that must accept a list of objects, each with a required `name` (string) and an optional `tags` attribute (map of strings). You want Terraform to reject any object that includes additional unexpected attributes. Which type constraint correctly enforces this?
You maintain a root module that instantiates a child module `network` for each AWS region defined in a local variable `regions` map. The module call uses `for_each = local.regions`. During a plan, Terraform reports that the module's `providers` argument references `each.key` in the `aws` provider alias. You want each module instance to use the AWS provider aliased to its own region. Which configuration correctly passes the region-specific provider instance into the module?
You are using a dynamic block to generate multiple ingress rules for an aws_security_group resource. The dynamic block iterates over a list of objects, each containing 'from_port', 'to_port', and 'cidr_blocks'. You need to access the current iteration's values inside the dynamic block. Which TWO of the following are valid ways to reference the current iteration object? (Choose two.)
You are authoring a module whose main configuration must merge a caller-supplied map of tags with a set of mandatory tags defined inside the module, giving the mandatory tags precedence when keys collide. The merged result is passed to the tags argument of an aws_instance resource. Which expression should you use?
You are using a dynamic block to generate multiple ingress rules for an AWS security group. The dynamic block iterates over a list of objects containing port, protocol, and cidr_blocks. Which two statements are true regarding the use of dynamic blocks in this scenario? (Choose two.)
A platform team stores environment definitions in a single variable "envs" typed as map(object({ region = string, instance_type = string, tags = map(string) })). They need to build locals for downstream modules. Which TWO local definitions correctly produce, respectively, a map of instance types keyed by environment name and a set of all distinct tag values across every environment? (Choose two.)
A platform team stores environment configuration in a single Terraform variable `env_config` of type `map(object({ cidr_block = string, az_count = number }))`. They want to create one `aws_subnet` per availability zone in each environment, with the subnet CIDR computed by calling `cidrsubnet` on the environment's `cidr_block`. Which expression produces a flattened collection suitable for `for_each` on `aws_subnet`, where each element's key uniquely identifies the environment and AZ index?
You are creating a Terraform module that must accept a list of objects representing AWS IAM policy statements. Each object has `effect`, `actions` (list of strings), and `resources` (list of strings). You want to validate that all `actions` and `resources` are non-empty lists and that `effect` is either "Allow" or "Deny". Which TWO of the following validation approaches are valid and correctly enforce these requirements? (Choose two.)
A configuration builds a local "az_map" with local.az_map = { for idx, az in data.aws_availability_zones.available.names : az => idx } and then uses for_each = local.az_map on aws_subnet resources. A reviewer asks what the resulting resource instance keys and values look like, and what happens if AWS later reorders the availability zone list. Which statement is accurate?
A configuration uses `for_each = toset(var.bucket_names)` on an `aws_s3_bucket` resource, where `var.bucket_names` is a `list(string)`. A teammate later reorders the list in a `.tfvars` file, and the plan shows unexpected bucket replacements. The team wants to keep using the list but avoid reordering churn. Which change best addresses the root cause while preserving the ability to add or remove buckets?
You are authoring a module that creates multiple AWS S3 buckets. The module receives a variable `bucket_configs` defined as `map(object({ versioning = bool, tags = map(string) }))`. You need to conditionally enable versioning only when the `versioning` attribute is true, and you also need to set tags dynamically from the object. Which combination of Terraform language features should you use to achieve this with minimal repetition?
You are using a `dynamic` block to generate multiple `ingress` rules for an AWS security group. The variable `ingress_rules` is a list of objects, each with `from_port`, `to_port`, and `cidr_blocks`. You need to ensure that the `cidr_blocks` attribute inside each generated `ingress` block is set correctly. Which TWO of the following statements about the `content` block within a `dynamic` block are true? (Choose two.)
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?
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?
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?
You 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?
Your 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?
You 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?
You 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?
You 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?
You 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?
You 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?
You 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?
A 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?
You 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?
You 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?
You 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?
A 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?
An 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?
You 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?
You 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?
You 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?
You 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?
A 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?
A 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?
A 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?
You 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?