The built-in function Fn::Cidr automatically creates an IP address range with a specific prefix length and returns an array of IPv4 CIDR blocks.
Declaration
JSON
{ "Fn::Cidr": [ "ipBlock", "count", "cidrBits" ] }
YAML
Syntax for the full function name:
Fn::Cidr: - ipBlock - count - cidrBits
Syntax for the short form:
!Cidr [ipBlock, count, cidrBits]
Parameters
ipBlock
: the original CIDR block to be split into smaller CIDR blocks.count
: the number of IPv4 CIDR blocks to generate. Valid values: 1 to 256. This is used to determine the final total number of subnets.cidrBits
: the number of subnet bits for the new CIDR block. For example, if you specify a value of "8" for this parameter, a CIDR block with a mask of "/24" is created.NoteThe subnet bit is the inverse of the subnet mask. To calculate the required host bits for given subnet bits, subtract the subnet bits from 32 for IPv4.
Return value
An array of CIDR blocks.
Examples
This example creates 6 CIDR blocks with a subnet mask "/27" inside from a CIDR block with a mask of "/24".
YAML
!Cidr - "192.168.0.0/24" - 6 - 5
JSON
{ "Fn::Cidr": [ "192.168.0.0/24", 6, 5 ] }
Return value: ['192.168.0.0/27', '192.168.0.32/27', '192.168.0.64/27', '192.168.0.96/27', '192.168.0.128/27', '192.168.0.160/27']