AWS CloudFormation
User Guide (Version )

AWS::EC2::VPCCidrBlock

Associates a CIDR block with your VPC. You can only associate a single IPv6 CIDR block with your VPC. The IPv6 CIDR block size is fixed at /56.

For more information about associating CIDR blocks with your VPC and applicable restrictions, see VPC and Subnet Sizing in the Amazon Virtual Private Cloud User Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::EC2::VPCCidrBlock", "Properties" : { "AmazonProvidedIpv6CidrBlock" : Boolean, "CidrBlock" : String, "VpcId" : String } }

YAML

Type: AWS::EC2::VPCCidrBlock Properties: AmazonProvidedIpv6CidrBlock: Boolean CidrBlock: String VpcId: String

Properties

AmazonProvidedIpv6CidrBlock

Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IPv6 addresses, or the size of the CIDR block.

Required: No

Type: Boolean

Update requires: Replacement

CidrBlock

An IPv4 CIDR block to associate with the VPC.

Required: No

Type: String

Update requires: Replacement

VpcId

The ID of the VPC.

Required: Yes

Type: String

Update requires: Replacement

Return Values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the VPC CIDR block.

For more information about using the Ref function, see Ref.

Examples

Associate an Amazon-provided IPv6 CIDR block

The following example associates an Amazon-provided IPv6 CIDR block (with a prefix length of /56) with the TestVPCIpv6 VPC.

JSON

"Ipv6VPCCidrBlock": { "Type": "AWS::EC2::VPCCidrBlock", "Properties": { "AmazonProvidedIpv6CidrBlock": true, "VpcId": { "Ref" : "TestVPCIpv6" } } }

YAML

Ipv6VPCCidrBlock: Type: AWS::EC2::VPCCidrBlock Properties: AmazonProvidedIpv6CidrBlock: true VpcId: !Ref TestVPCIpv6

Associate an IPv4 CIDR block and Amazon-provided IPv6 CIDR block

The following example associates an IPv4 CIDR block and an Amazon-provided IPv6 CIDR block with a VPC. It also outputs the list of IPv4 CIDR block association IDs and IPv6 CIDR blocks that are associated with the VPC.

JSON

{ "Resources": { "VPC": { "Type": "AWS::EC2::VPC", "Properties": { "CidrBlock": "10.0.0.0/24" } }, "VpcCidrBlock": { "Type": "AWS::EC2::VPCCidrBlock", "Properties": { "VpcId": { "Ref": "VPC" }, "CidrBlock": "192.0.0.0/24" } }, "VpcCidrBlockIpv6": { "Type": "AWS::EC2::VPCCidrBlock", "Properties": { "VpcId": { "Ref": "VPC" }, "AmazonProvidedIpv6CidrBlock": true } } }, "Outputs": { "VpcId": { "Value": { "Ref": "VPC" } }, "PrimaryCidrBlock": { "Value": { "Fn::GetAtt": [ "VPC", "CidrBlock" ] } }, "Ipv6CidrBlock": { "Value": { "Fn::Select": [ 0, { "Fn::GetAtt": [ "VPC", "Ipv6CidrBlocks" ] } ] } }, "CidrBlockAssociation": { "Value": { "Fn::Select": [ 0, { "Fn::GetAtt": [ "VPC", "CidrBlockAssociations" ] } ] } } } }

YAML

Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/24 VpcCidrBlock: Type: AWS::EC2::VPCCidrBlock Properties: VpcId: !Ref VPC CidrBlock: 192.0.0.0/24 VpcCidrBlockIpv6: Type: AWS::EC2::VPCCidrBlock Properties: VpcId: !Ref VPC AmazonProvidedIpv6CidrBlock: true Outputs: VpcId: Value: !Ref VPC PrimaryCidrBlock: Value: !GetAtt VPC.CidrBlock Ipv6CidrBlock: Value: !Select [ 0, !GetAtt VPC.Ipv6CidrBlocks ] CidrBlockAssociation: Value: !Select [ 0, !GetAtt VPC.CidrBlockAssociations ]