shan
shan

Reputation: 115

When I run cidrsubnet function in terraform I am getting 'prefix extension of 3 does not accommodate a subnet numbered 8'. Why is this?

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

Answers (1)

Marcin
Marcin

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:

  • 10.1.0.0/24
  • 10.1.1.0/24
  • 10.1.2.0/24
  • 10.1.3.0/24
  • 10.1.4.0/24
  • 10.1.5.0/24
  • 10.1.6.0/24
  • 10.1.7.0/24

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

Related Questions