Skip to content

Commit

Permalink
Update requiredXor for Vpc and Subnets (#3734)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Oct 3, 2024
1 parent ced6ec3 commit 2fecc9a
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scripts/update_schemas_manually.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,10 @@
path="/",
values={
"requiredXor": ["CidrBlock", "Ipv4IpamPoolId"],
"dependentRequired": {"Ipv4IpamPoolId": ["Ipv4NetmaskLength"]},
"dependentRequired": {
"Ipv4IpamPoolId": ["Ipv4NetmaskLength"],
"Ipv4NetmaskLength": ["Ipv4IpamPoolId"],
},
},
),
],
Expand Down Expand Up @@ -1631,10 +1634,15 @@
patches=[
Patch(
values={
"requiredXor": ["CidrBlock", "Ipv4IpamPoolId"],
"dependentExcluded": {
"AvailabilityZone": ["AvailabilityZoneId"],
"AvailabilityZoneId": ["AvailabilityZone"],
},
"dependentRequired": {
"Ipv4IpamPoolId": ["Ipv4NetmaskLength"],
"Ipv4NetmaskLength": ["Ipv4IpamPoolId"],
},
},
path="/",
),
Expand Down
1 change: 1 addition & 0 deletions scripts/update_snapshot_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cfn-lint test/fixtures/templates/integration/getatt-types.yaml -e -c I --format
cfn-lint test/fixtures/templates/integration/aws-ec2-networkinterface.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-networkinterface.json
cfn-lint test/fixtures/templates/integration/aws-ec2-instance.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-instance.json
cfn-lint test/fixtures/templates/integration/aws-ec2-launchtemplate.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-launchtemplate.json
cfn-lint test/fixtures/templates/integration/aws-ec2-subnet.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-subnet.json
cfn-lint test/fixtures/templates/integration/aws-dynamodb-table.yaml -e -c I --format json > test/fixtures/results/integration/aws-dynamodb-table.json

# public/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[
{
"op": "add",
"path": "/requiredXor",
"value": [
"CidrBlock",
"Ipv4IpamPoolId"
]
},
{
"op": "add",
"path": "/dependentExcluded",
Expand All @@ -10,5 +18,17 @@
"AvailabilityZone"
]
}
},
{
"op": "add",
"path": "/dependentRequired",
"value": {
"Ipv4IpamPoolId": [
"Ipv4NetmaskLength"
],
"Ipv4NetmaskLength": [
"Ipv4IpamPoolId"
]
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"value": {
"Ipv4IpamPoolId": [
"Ipv4NetmaskLength"
],
"Ipv4NetmaskLength": [
"Ipv4IpamPoolId"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"AvailabilityZone"
]
},
"dependentRequired": {
"Ipv4IpamPoolId": [
"Ipv4NetmaskLength"
],
"Ipv4NetmaskLength": [
"Ipv4IpamPoolId"
]
},
"primaryIdentifier": [
"/properties/SubnetId"
],
Expand Down Expand Up @@ -134,6 +142,10 @@
"required": [
"VpcId"
],
"requiredXor": [
"CidrBlock",
"Ipv4IpamPoolId"
],
"tagging": {
"cloudFormationSystemTags": true,
"tagOnCreate": true,
Expand Down
12 changes: 12 additions & 0 deletions src/cfnlint/data/schemas/providers/us_east_1/aws-ec2-subnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"AvailabilityZone"
]
},
"dependentRequired": {
"Ipv4IpamPoolId": [
"Ipv4NetmaskLength"
],
"Ipv4NetmaskLength": [
"Ipv4IpamPoolId"
]
},
"primaryIdentifier": [
"/properties/SubnetId"
],
Expand Down Expand Up @@ -135,6 +143,10 @@
"required": [
"VpcId"
],
"requiredXor": [
"CidrBlock",
"Ipv4IpamPoolId"
],
"tagging": {
"cloudFormationSystemTags": true,
"tagOnCreate": true,
Expand Down
3 changes: 3 additions & 0 deletions src/cfnlint/data/schemas/providers/us_east_1/aws-ec2-vpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"dependentRequired": {
"Ipv4IpamPoolId": [
"Ipv4NetmaskLength"
],
"Ipv4NetmaskLength": [
"Ipv4IpamPoolId"
]
},
"primaryIdentifier": [
Expand Down
86 changes: 86 additions & 0 deletions test/fixtures/results/integration/aws-ec2-subnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"Filename": "test/fixtures/templates/integration/aws-ec2-subnet.yaml",
"Id": "5c96f1f9-9dfc-31e7-f24b-9e08af46c98f",
"Level": "Error",
"Location": {
"End": {
"ColumnNumber": 15,
"LineNumber": 7
},
"Path": [
"Resources",
"Subnet1",
"Properties"
],
"Start": {
"ColumnNumber": 5,
"LineNumber": 7
}
},
"Message": "'Ipv4IpamPoolId' is a dependency of 'Ipv4NetmaskLength'",
"ParentId": null,
"Rule": {
"Description": "When certain properties are specified it results in other properties to be required",
"Id": "E3021",
"ShortDescription": "Validate that when a property is specified that other properties should be included",
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#dependentrequired"
}
},
{
"Filename": "test/fixtures/templates/integration/aws-ec2-subnet.yaml",
"Id": "5c12a390-4b88-f609-d6d6-bd7fa2250f99",
"Level": "Error",
"Location": {
"End": {
"ColumnNumber": 15,
"LineNumber": 13
},
"Path": [
"Resources",
"Subnet2",
"Properties"
],
"Start": {
"ColumnNumber": 5,
"LineNumber": 13
}
},
"Message": "Only one of ['CidrBlock', 'Ipv4IpamPoolId'] is a required property",
"ParentId": null,
"Rule": {
"Description": "Make sure that Resources properties that are required exist. Along with other properties not being specified",
"Id": "E3014",
"ShortDescription": "Validate only one of a set of required properties are specified",
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#requiredxor"
}
},
{
"Filename": "test/fixtures/templates/integration/aws-ec2-subnet.yaml",
"Id": "7a696880-e120-60b6-93b9-a57a48d71189",
"Level": "Error",
"Location": {
"End": {
"ColumnNumber": 15,
"LineNumber": 17
},
"Path": [
"Resources",
"Subnet3",
"Properties"
],
"Start": {
"ColumnNumber": 5,
"LineNumber": 17
}
},
"Message": "'Ipv4NetmaskLength' is a dependency of 'Ipv4IpamPoolId'",
"ParentId": null,
"Rule": {
"Description": "When certain properties are specified it results in other properties to be required",
"Id": "E3021",
"ShortDescription": "Validate that when a property is specified that other properties should be included",
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#dependentrequired"
}
}
]
19 changes: 19 additions & 0 deletions test/fixtures/templates/integration/aws-ec2-subnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Parameters:
Vpc:
Type: AWS::EC2::VPC::Id
Resources:
Subnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: 10.0.0.0/24
Ipv4NetmaskLength: 10
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
Subnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
Ipv4IpamPoolId: test
7 changes: 7 additions & 0 deletions test/integration/test_integration_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class TestQuickStartTemplates(BaseCliTestCase):
),
"exit_code": 2,
},
{
"filename": ("test/fixtures/templates/integration/aws-ec2-subnet.yaml"),
"results_filename": (
"test/fixtures/results/integration/aws-ec2-subnet.json"
),
"exit_code": 2,
},
{
"filename": ("test/fixtures/templates/integration/aws-dynamodb-table.yaml"),
"results_filename": (
Expand Down

0 comments on commit 2fecc9a

Please sign in to comment.