Interview Prep/Networking/Cloud networking: VPC, firewalls, NAT, VPN and proxies

`terraform apply` fails with `RulesPerSecurityGroupLimitExceeded: The maximum number of rules per security group has been reached`.

BeginnerTroubleshootingCloud networking: VPC, firewalls, NAT, VPN and proxies
Answer

Likely causes → An SG has a default quota of 60 inbound and 60 outbound rules (each CIDR counts as a rule). Allow-listing many partner IPs or CDN ranges one by one hits it quickly.

Diagnose →

aws ec2 describe-security-groups --group-ids <sg> --query 'length(SecurityGroups[0].IpPermissions[].IpRanges[])'
aws service-quotas get-service-quota --service-code vpc --quota-code L-0EA8095F

Fix → Use managed prefix lists (one reference counts as rules equal to its max entries, but is much easier to manage), AWS-managed prefix lists (e.g. CloudFront origin-facing), split rules across SGs, or request a quota increase (rules × SGs per ENI is capped at 1000).

Prevent → Reference SGs and prefix lists instead of raw CIDRs; review rules that grow from ad-hoc requests.

All Networking questions Roadmap: Networking for DevOps

More on Cloud networking: VPC, firewalls, NAT, VPN and proxies