armaka
armaka

Reputation: 264

Is it possible to let AWS assign CIDR block for you based on block size and VPC CIDR?

When I create an AWS Cloudformation stack I declare in the Resources field:

Resources:

  SubnetPublic:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: !Ref CidrBlockPublic
      VpcId: !Ref VPC
      MapPublicIpOnLaunch: True

      Tags:
        - Key: Name
          Value: !Sub "${DomainName}-public"

But having statically declared CidrBlockPublic is not very convenient and human-error prone. Is the an approach where AWS could calculate the right CIDR block within the VPC CIDR? For example:

I would have VPC CIDR as 10.0.0.0/16 and I wish to have subnet CIDR size of 8. So when I create a subnet inside VPC, the AWS would take that size into account and create 8-host sized network (for example, 10.0.2.0/29 or 10.0.1.100/29 etc...)

Upvotes: 1

Views: 200

Answers (1)

Marcin
Marcin

Reputation: 238557

You can use Fn::Cidr to autogenerate CIDR ranges. There is nothing else, unless you implement your own solution in the form of macros.

Upvotes: 1

Related Questions