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...)
CodePudding user response:
You can use Fn::Cidr to autogenerate CIDR ranges. There is nothing else, unless you implement your own solution in the form of macros.