Skip to content

Commit

Permalink
Fix subnet CIDR range validation (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: Mahendra Korepu <[email protected]>
  • Loading branch information
mahendra-rk authored Aug 19, 2021
1 parent 132ab52 commit d4caf5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cdpctl/validation/infra/validate_aws_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def aws_public_subnets_range_validation() -> None:
subnets_wo_valid_range = []
for subnet in subnets_data["public_subnets"]:
cidrblock_range = subnet["CidrBlock"].split("/")[1]
if int(cidrblock_range) < 24:
if int(cidrblock_range) > 24:
subnets_wo_valid_range.append(subnet["SubnetId"])

if len(subnets_wo_valid_range) > 0:
Expand Down Expand Up @@ -423,7 +423,7 @@ def aws_private_subnets_range_validation() -> None:
subnets_wo_valid_range = []
for subnet in subnets_data["private_subnets"]:
cidrblock_range = subnet["CidrBlock"].split("/")[1]
if int(cidrblock_range) < 19:
if int(cidrblock_range) > 19:
subnets_wo_valid_range.append(subnet["SubnetId"])

if len(subnets_wo_valid_range) > 0:
Expand Down
16 changes: 8 additions & 8 deletions tests/validation/infra/test_validate_aws_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
{
"AvailabilityZone": "us-west-2c",
"CidrBlock": "10.1.238.0/24",
"CidrBlock": "10.1.238.0/14",
"SubnetId": "subnet-pubtest2-cdp",
"VpcId": "vpc-testcdp12345",
"Tags": [
Expand All @@ -89,7 +89,7 @@
},
{
"AvailabilityZone": "us-west-2a",
"CidrBlock": "10.2.236.0/24",
"CidrBlock": "10.2.236.0/22",
"SubnetId": "subnet-pubtest3-cdp",
"VpcId": "vpc-testcdp12345",
"Tags": [
Expand All @@ -104,7 +104,7 @@
"Subnets": [
{
"AvailabilityZone": "us-west-2b",
"CidrBlock": "20.0.237.0/24",
"CidrBlock": "20.0.237.0/14",
"SubnetId": "subnet-prvtest1-cdp",
"VpcId": "vpc-testcdp12345",
"Tags": [
Expand All @@ -114,7 +114,7 @@
},
{
"AvailabilityZone": "us-west-2c",
"CidrBlock": "20.1.238.0/24",
"CidrBlock": "20.1.238.0/19",
"SubnetId": "subnet-prvtest2-cdp",
"VpcId": "vpc-testcdp12345",
"Tags": [
Expand All @@ -124,7 +124,7 @@
},
{
"AvailabilityZone": "us-west-2a",
"CidrBlock": "20.2.236.0/24",
"CidrBlock": "20.2.236.0/18",
"SubnetId": "subnet-prvtest3-cdp",
"VpcId": "vpc-testcdp12345",
"Tags": [
Expand Down Expand Up @@ -520,7 +520,7 @@ def test_aws_public_subnets_range_validation_failure(ec2_client: EC2Client) -> N
{
"Subnets": [
{
"CidrBlock": "10.0.237.0/14",
"CidrBlock": "10.0.237.0/25",
"SubnetId": "subnet-pubtest1-cdp",
},
{"CidrBlock": "10.1.238.0/24", "SubnetId": "subnet-pubtest2-cdp"},
Expand Down Expand Up @@ -935,12 +935,12 @@ def test_aws_private_subnets_range_validation_failure(ec2_client: EC2Client) ->
{
"Subnets": [
{
"CidrBlock": "10.0.237.0/18",
"CidrBlock": "10.0.237.0/12",
"SubnetId": "subnet-prvtest1-cdp",
},
{"CidrBlock": "10.1.238.0/24", "SubnetId": "subnet-prvtest2-cdp"},
{
"CidrBlock": "10.2.236.0/14",
"CidrBlock": "10.2.236.0/24",
"SubnetId": "subnet-prvtest3-cdp",
},
],
Expand Down

0 comments on commit d4caf5c

Please sign in to comment.