Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

Fn::Cidr

The intrinsic function Fn::Cidr returns the specified Cidr address block.

Declaration

JSON

{ "Fn::Cidr" : [ipBlock, count, sizeMask]}

YAML

Syntax for the full function name:

Fn::Cidr: [ ipBlock, count, sizeMask ]

Syntax for the short form:

!Cidr [ ipBlock, count, sizeMask ]

Parameters

ipBlock

The user-specified default Cidr address block.

count

The number of subnets' Cidr block wanted. Count can be 1 to 256.

sizeMask

Optional. The digit covered in the subnet.

Return Value

The specified Cidr block.

Example

YAML

AWSTemplateFormatVersion: 2010-09-09 Parameters: cidrBlock : Type : String count: Type : String maskSizeForIPv4: Type: String maskSizeForIPv6: Type: String Resources: Subnet1: Type: AWS::EC2::Subnet Properties: AssignIPv6AddressOnCreation: true VpcId: !Ref VPC #Test Ipv4 CidrBlock CidrBlock: !Select [0, !Cidr [!Ref cidrBlock, !Ref count, !Ref maskSizeForIPv4]] #Test Ipv6 CidrBlock Ipv6CidrBlock: !Select [0, !Cidr [!Select [0, !GetAtt VPC.Ipv6CidrBlocks], !Ref count, !Ref maskSizeForIPv6]] DependsOn: Ipv6VPCCidrBlock Subnet2: Type: AWS::EC2::Subnet Properties: AssignIPv6AddressOnCreation: true VpcId: !Ref VPC #Test Ipv4 CidrBlock CidrBlock: !Select [1, !Cidr [!Ref cidrBlock, !Ref count, !Ref maskSizeForIPv4]] #Test Ipv6 CidrBlock Ipv6CidrBlock: !Select [1, !Cidr [!Select [0, !GetAtt VPC.Ipv6CidrBlocks], !Ref count, !Ref maskSizeForIPv6]] DependsOn: Ipv6VPCCidrBlock VPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref cidrBlock Ipv6VPCCidrBlock: Type: AWS::EC2::VPCCidrBlock Properties: AmazonProvidedIpv6CidrBlock: true VpcId: !Ref VPC

Supported Functions

You can use the following functions in a Fn::Cidr function: