A module sets instance_type = lookup(var.instance_sizes, var.environment, "t3.micro"), where instance_sizes is {dev = "t3.small", prod = "m5.large"} and environment is staging. What value does the expression produce?
Select an answer to reveal the explanation.
Short Explanation
lookup() is like asking for a menu item with a backup order: if they don't have it, you get your backup. staging isn't on the menu, so you get t3.micro. The trap is expecting an error, which only happens with plain index syntax or a missing default.
Full Explanation
lookup(map, key, default) retrieves the value for the given key, and when the key is not present it returns the default argument instead. Because staging is not a key in instance_sizes, the expression returns t3.micro. This makes lookup with a default a concise way to express optional per-environment overrides with a baseline value. lookup does not fail on a missing key when a default is supplied; the failure behaviour belongs to direct index syntax such as var.instance_sizes[var.environment], which raises an error for an absent key. It does not return null for a missing key; null would only be the result if null were passed as the default. It also never falls back to an existing entry: map keys are not used as defaults, and choosing one by sort order would make results arbitrary. Exam caveat: the default must be compatible with the map's element type, and when every environment must be listed explicitly, index syntax that fails loudly is often the safer design than a silent default. Operational check: in terraform console, evaluate the expression for each environment value, including one that is missing, to confirm which value each produces before applying.