Reputation: 115
code:
cidrsubnet("10.1.2.0/21", 3, 8)
Issue:
When I run this in terraform I am getting prefix extension of 3 does not accommodate a subnet numbered 8. Why is this? Anything below 8 works. I've followed the following example: Configure subnets using terraform cidrsubnet But not sure what I am missing here....
Upvotes: 3
Views: 1908
Reputation: 238747
When you are using cidrsubnet("10.1.2.0/21", 3, 8)
, you are adding 3 bits. Since in binary 2 ^ 3 = 8
, you can define maximally 8 subnets in this range: 0,1,2,..., 7 with the following cidrs:
If you want to define subnets between 0 and 15, you have to use: cidrsubnet("10.1.2.0/21", 4, 8)
, since 2 ^ 4 = 16
and you can have sixteen subnets: 0, 1, 2, ..., 15.
Upvotes: 5