Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

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

lex000c4431210154
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisioner.java
index 478f1c67da..8e1ddcaca0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisioner.java
@@ -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,
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisionerTest.java
index d676ea9888..79be86d187 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkAclCfnProvisionerTest.java
@@ -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