yoklainterview sim

DevOps / Cloud Terraform Hcl Language Expressions Interview Questions

75 verified DevOps / Cloud Terraform Hcl Language Expressions interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Terraform Hcl Language ExpressionsDifficulty 1
In a Terraform resource block like resource "aws_instance" "web" { ami = "ami-123" }, what do the two quoted strings after resource represent?
  • aThe AWS region and the availability zone — inconsistent with the actual semantics of this feature
  • bThe resource type and the local name used to reference this resource elsewhere in the configuration
  • cThe provider name and the Terraform version constraint — not how Terraform actually behaves here
  • dThe variable name and its default value — this misdescribes the tool's actual, documented behavior
Explanation:The first string is the resource type (e.g. aws_instance), which tells Terraform which provider resource to create; the second is the local name (e.g. web), used to reference the resource as aws_instance.web elsewhere in the same module.
Terraform Hcl Language ExpressionsDifficulty 1
resource "aws_instance" "srv" {
  count = 3
  ami   = "ami-123"
}

How many aws_instance resources does this configuration create?
  • a1, because count only sets a variable, it doesn't multiply resources — this misdescribes the tool's actual, documented behavior
  • b0, because count requires an explicit list of values to iterate over — something Terraform does not actually guarantee in this situation
  • c3 separate instances, addressed as aws_instance.srv[0], aws_instance.srv[1], aws_instance.srv[2]
  • dInfinite instances, since count without a for_each has no upper bound — not how Terraform actually behaves here
Explanation:Setting count = 3 on a resource tells Terraform to create three instances of that resource, each addressed with a numeric index: aws_instance.srv[0], [1], [2].
Terraform Hcl Language ExpressionsDifficulty 1
resource "aws_instance" "srv" {
  count = 3
  tags = { Name = "srv-${count.index}" }
}

What values does count.index take across the three created instances?
  • a0, 1, 2 — a zero-based numeric index unique to each instance
  • b1, 2, 3 — a one-based numeric index
  • cThe literal string "count.index" for all three instances
  • dA random UUID generated separately for each instance
Explanation:count.index is a zero-based integer available inside a resource that uses count, giving each created instance a distinct index (0, 1, 2 for count = 3), commonly used to build unique names or pick values from a list.
Terraform Hcl Language ExpressionsDifficulty 2
What kind of value must be given to for_each on a resource block?
  • aAny ordered list of numbers
  • bA single string value only
  • cA nested block reference to another resource's count
  • dA map, or a set of strings
Explanation:for_each accepts a map (iterating over key/value pairs) or a set of strings (iterating over unique string values); it does not accept a plain list or a single scalar value directly.
Terraform Hcl Language ExpressionsDifficulty 2
resource "aws_iam_user" "u" {
  for_each = toset(["alice", "bob"])
  name     = each.value
}

How is each created resource addressed?
  • aaws_iam_user.u[0] and aws_iam_user.u[1], using numeric indices — this misdescribes the tool's actual, documented behavior
  • baws_iam_user.u["alice"] and aws_iam_user.u["bob"], using the set values as string keys
  • caws_iam_user.u.alice and aws_iam_user.u.bob, as separate top-level resources
  • dA single aws_iam_user.u resource containing both names internally — not how Terraform actually behaves here
Explanation:When for_each is given a set of strings, Terraform addresses each instance using that string as its key, e.g. aws_iam_user.u["alice"], unlike count, which uses a numeric index.
Terraform Hcl Language ExpressionsDifficulty 1
What is the main purpose of a dynamic block in Terraform?
  • aTo generate a variable number of repeated nested blocks (like multiple ingress blocks) based on a collection
  • bTo dynamically change the provider used by a resource at apply time — inconsistent with the actual semantics of this feature
  • cTo allow a resource to be created only when running in dynamic (non-static) IP mode — this contradicts how the mechanism is actually documented to work
  • dTo mark a variable as dynamically typed instead of statically typed — a common misconception not matched by Terraform's real behavior
Explanation:A dynamic block lets you programmatically generate multiple nested configuration blocks (such as several ingress/egress rules inside a security group) from a list or map, instead of writing each one out by hand.

Test yourself against the 3375-question DevOps / Cloud bank.

Start interview