A network module computes subnet addresses with cidrsubnet(). What does cidrsubnet("10.0.0.0/16", 8, 2) return?
Select an answer to reveal the explanation.
Short Explanation
cidrsubnet() is slicing a pizza: newbits says how many extra bits of prefix you add, and netnum says which slice you take. Add 8 bits to a /16 and you get /24 slices; take slice number 2. The trap is treating newbits as the address instead of the prefix extension.
Full Explanation
cidrsubnet(prefix, newbits, netnum) extends the given prefix by newbits bits and returns the subnet whose number in that new range is netnum. Starting from 10.0.0.0/16, adding 8 bits produces a /24 prefix, which divides the space into 256 subnets numbered 0 to 255 in the third octet. Subnet number 2 is therefore 10.0.2.0/24. The function returns a CIDR string, so modules commonly call it with count.index or each value's position to carve consistent subnets from a VPC range. Reading the newbits value of 8 as the subnet number gives 10.0.8.0/24, which mixes up the two arguments. Placing the 2 in the second octet ignores the fact that the existing /16 prefix fixes the first two octets and the new bits come immediately after them. Keeping the original /16 length ignores the extension entirely; the result always has prefix length equal to the original plus newbits. Exam caveat: netnum must fit within the newbits range, so a value of 256 with 8 new bits is an error, and overlapping ranges arise easily when different newbits values are mixed. Operational check: evaluate the expression and neighbouring netnum values in terraform console before applying a subnet layout.