sebastian
sebastian

Reputation: 2348

Terraform cidrsubnet function

First of all, I apologize for now knowing how to subnet better. It's not something I've had to do up until now.

I have been given a network/cidr of 10.10.32.0/19.

I have 6 subnets that need 255 ips each.

The rest of the IPs I would like to spread across 3 remaining subnets.

This is what i came up with using cidrsubnet

        cidrsubnet("10.10.32.0/19", 2, 0) # "10.10.64.0/21" 2048 hosts
        cidrsubnet("10.10.32.0/19", 2, 1) # "10.10.72.0/21" 2048 hosts
        cidrsubnet("10.10.32.0/19", 2, 2) # "10.10.80.0/21" 2048 hosts

        cidrsubnet("10.10.32.0/19", 5, 24) # "10.10.88.0/24" 255 hosts
        cidrsubnet("10.10.32.0/19", 5, 25) # "10.10.89.0/24" 255 hosts
        cidrsubnet("10.10.32.0/19", 5, 26) # "10.10.90.0/24" 255 hosts

        cidrsubnet("10.10.32.0/19", 5, 27) # "10.10.91.0/24" 255 hosts
        cidrsubnet("10.10.32.0/19", 5, 28) # "10.10.92.0/24" 255 hosts
        cidrsubnet("10.10.32.0/19", 5, 29) # "10.10.93.0/24" 255 hosts

This leaves me with about 512 ips that can't be used. Am I doing this right?

Upvotes: 1

Views: 545

Answers (1)

DazWilkin
DazWilkin

Reputation: 40326

You have 2^11 (32-19) hosts == 8192

Your range begins at 10.10.32.0 and runs through 10.10.63.255

6*256+3*2048 == 7680 leaving the 512

You'll need to rebalance so you don't waste IPs.

Your first cidrsubnet(10.10.32/19,2,0) is 10.10.32.0--10.10.39.255

Upvotes: 2

Related Questions