All Projects → aws-samples → aws-cidr-finder

aws-samples / aws-cidr-finder

Licence: Apache-2.0 license
A lambda function, a cloudformation template to get it running, and example templates showing how to use a custom resource (calling the lambda) to automatically calculate CIDR ranges for subnets based on the VPC range.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

CIDR finder

AWS CIDR Finder is a tool for adding more convenience to your AWS CloudFormation templates and AWS Service Catalog products by calculating the CIDR ranges of new subnets for you so that your users don't have to supply them.

In the DevOps world, where automation rules, the exact IP addresses of your servers don't really matter when they can otherwise be identified by tagging or API calls. For that reason, when launching CloudFormation stacks, it's good to have an option not to have to specify the CIDR ranges for your subnets.

AWS CIDR finder provides a Lambda function that can be used as a custom resource within your own CloudFormation templates to calculate CIDR ranges.

Usage

First of all, you need to install AWS CIDR finder in your account. The included install.sh script will create the lambda function for you and provide an exported CloudFormation value that you can make use of in your own templates.

Example CloudFormation template

The following example is included in full in the cfn directory and creates a new VPC along with 3 new subnets using automatically calculated CIDR ranges.

Resources:
  # Create a new VPC for the example
  Vpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 192.168.0.0/23

  # Call the custom resource, specify 3 subnets of different sizes.
  # The resource will have properties called CidrBlock1, CidrBlock2, and CidrBlock3 to contain the 3 CIDR block definitions
  CidrFindr:
    Type: Custom::CidrFindr
    Properties:
      ServiceToken: !ImportValue CidrFindr
      VpcId: !Ref Vpc  # Refer to the VPC created above
      Sizes: [24, 25, 26]  # 3 subnets of differing sizes

  # Use the first cidr block from the CidrFindr resource
  Subnet1:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: !GetAtt CidrFindr.CidrBlock1
      VpcId: !Ref Vpc
      
  # Use the second cidr block from the CidrFindr resource
  Subnet2:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: !GetAtt CidrFindr.CidrBlock2
      VpcId: !Ref Vpc
      
  # Use the third cidr block from the CidrFindr resource
  Subnet3:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: !GetAtt CidrFindr.CidrBlock3
      VpcId: !Ref Vpc
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].