Giter Club home page Giter Club logo

aws-cidr-finder's Introduction

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

aws-cidr-finder's People

Contributors

mpreziuso avatar ovalba avatar stilvoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-cidr-finder's Issues

Lambda function returns an invalid subnet size error

Hi,

This looks like something I could really make use of but your example success template returns "An invalid subnet size was specified: 24, 25, 26". I tried some other valid combinations but nothing works.

I checked the code and subnet size check looks ok to me. (I am not a python expert though!)

# Check the sizes are valid
if any(size < 16 or size > 28 for size in sizes):
    return send_response(event, context, "FAILED", reason="An invalid subnet size was specified: {}".format(", ".join(sizes)))

You may want to consider updating the role so the function can send logs to cloudwatch.

Thanks!

Not enough information to determine IP rage

Hello guys. Trying pretty hard to get this working on our account, and whenever I call this using a custom resource in subsequent cfn templates, we're getting this output from the Lambda Function:

Not enough information to determine IP range: Exception
Traceback (most recent call last):
File "/var/task/lambda.py", line 78, in lambda_handler
result = find_next_subnet(vpc_cidr, subnet_cidrs, sizes)
File "/var/task/cidr_findr.py", line 86, in find_next_subnet
attempt = Range(base=vpc.base, size=req)
File "/var/task/cidr_findr.py", line 64, in __init__
raise Exception("Not enough information to determine IP range")
Exception: Not enough information to determine IP range

Pretty sure we're passing everything in correctly, here's the corresponding custom resource:

  CidrFindr:
    Type: Custom::CidrFindr
    Properties:
      ServiceToken: !ImportValue CidrFindr
      VpcId: !Ref myVpc
      Sizes: [27,27,27]

For what it's worth, I also created a custom test request using the AWS console (using the CloudFormation request format) and still get the same thing. I'm not super great at Python so really banging my head trying to understand where it's failing.

Returns cidrs that are already in use.

It worked the first time. But now when using in a new stack it returns a cidr that is either identical or within the range from the results provided to the first stack that used it.

`
The CIDR '10.10.16.0/24' conflicts with another subnet

`

Please add support for VPCs with multiple CIDR blocks

Please add support for VPCs that have multiple CIDR blocks associated.

Desired behaviour - when looking for an available subnet slot, keep searching through all associated CIDR blocks in order until slot is found, or the search has reached the end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.