fix(cloudformation): read network ACL entry PortRange and RuleNumber with resolveOptionalInt (#6724)

This commit is contained in:
lex00 authored and GitHub committed 2026-10-27 10:26:21 -04:00
1 parent 77f2477641
commit 0c44312101
2 files changed
+24 -6

No files matched your search

@@ -92,14 +92,12 @@ public class Ec2NetworkAclCfnProvisioner implements CfnResourceProvisioner {
private void provisionNetworkAclEntry(StackResource r, JsonNode props, ProvisionContext ctx) {
String aclId = ctx.resolveOptional(props, "NetworkAclId");
String ruleNumberValue = ctx.resolveOptional(props, "RuleNumber");
int ruleNumber = ruleNumberValue != null ? Integer.parseInt(ruleNumberValue) : 100;
Integer ruleNumberValue = ctx.resolveOptionalInt(props, "RuleNumber");
int ruleNumber = ruleNumberValue != null ? ruleNumberValue : 100;
boolean egress = Boolean.parseBoolean(ctx.resolveOptional(props, "Egress"));
JsonNode portRange = props != null && props.hasNonNull("PortRange") ? props.get("PortRange") : null;
String fromValue = ctx.resolveOptional(portRange, "From");
String toValue = ctx.resolveOptional(portRange, "To");
Integer from = fromValue != null ? Integer.valueOf(fromValue) : null;
Integer to = toValue != null ? Integer.valueOf(toValue) : null;
Integer from = ctx.resolveOptionalInt(portRange, "From");
Integer to = ctx.resolveOptionalInt(portRange, "To");
JsonNode icmp = props != null && props.hasNonNull("Icmp") ? props.get("Icmp") : null;
String protocol = ctx.resolveOptional(props, "Protocol");
ec2Service.createNetworkAclEntry(ctx.region(), aclId, ruleNumber,
@@ -193,6 +193,26 @@ class Ec2NetworkAclCfnProvisionerTest {
"0.0.0.0/0", null, null, null, null, null, true);
}
@Test
void aclEntryOmitsPortRangeAndRuleNumberThatResolveToNoValue() {
StackResource r = resource("AWS::EC2::NetworkAclEntry", "Entry");
ObjectNode props = mapper.createObjectNode()
.put("NetworkAclId", "acl-abc")
.put("Protocol", "6")
.put("RuleAction", "allow")
.put("CidrBlock", "0.0.0.0/0");
props.set("RuleNumber", mapper.createObjectNode().put("Ref", "AWS::NoValue"));
ObjectNode portRange = mapper.createObjectNode();
portRange.set("From", mapper.createObjectNode().put("Ref", "AWS::NoValue"));
portRange.set("To", mapper.createObjectNode().put("Ref", "AWS::NoValue"));
props.set("PortRange", portRange);
provisioner.provision(r, props, ctx());
verify(ec2).createNetworkAclEntry("us-east-1", "acl-abc", 100, "6", "allow", false,
"0.0.0.0/0", null, null, null, null, null, true);
}
/**
* Id is the type's primaryIdentifier and its only schema readOnlyProperty. It went unset for a
* long time because the sibling NetworkAcl arm sets one too, and the coverage scan read the