when I select VPC network, how can I assign the VPC's CIDR to Security Groups?
Parameters:
VpcId:
Type: 'AWS::EC2::VPC::Id'
Description: VpcId of your existing Virtual Private Cloud (VPC)
ConstraintDescription: must be the VPC Id of an existing Virtual Private Cloud.
EC2SecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VpcId
GroupDescription: SecurityGroup
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp:
Thanks for helps.
You can't get VPC CIDR range based on its Id passed as a parameter. You either have to pass the CIDR as a second parameter, or construct a custom resource to do this for you.
The custom resource would be a lambda function, which would take the VPC id as an input parameter. Then using AWS SDK, the function would query the VPC and return its CIDR to your CloudFormation to be used in your security group.