mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 18:48:00 -05:00
fix(elbv2): answer a single-subnet ALB with ValidationError (#6098)
* test(elbv2): expect ValidationError for a single-subnet ALB AWS answers a CreateLoadBalancer for an Application Load Balancer with one subnet with ValidationError (400) "At least two subnets in two different Availability Zones must be specified", the answer it gives one with none, and it counts the subnets before it looks them up. Floci answers InvalidConfigurationRequest with a message of its own. - ElbV2ServiceTest, ElbV2IntegrationTest (Query protocol), CloudFormationElbV2SubnetMappingsIntegrationTest and the compatibility suite's ElbV2Test expect that error, and no balancer, for one subnet in Subnets or SubnetMappings, with or without Type, and for one subnet that does not exist. A Network or Gateway Load Balancer on one subnet is still created. - The tests that sent an Application Load Balancer one missing subnet to get SubnetNotFound now send it an existing subnet as well, or ask for a Network Load Balancer, so they still reach the subnet lookup. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(elbv2): answer a single-subnet ALB with ValidationError CreateLoadBalancer for an Application Load Balancer with one subnet now answers ValidationError (400) "At least two subnets in two different Availability Zones must be specified", as AWS does, instead of InvalidConfigurationRequest with a message of Floci's own. requireSubnets, which already refused a balancer with no subnets this way, now refuses an Application Load Balancer with fewer than two. It runs before any subnet is looked up, so one subnet that does not exist gets the same answer, as on AWS. One SubnetMappings entry goes through the same check, following the rule the API reference states for both fields. CloudFormation creates and replacements go through it too. A Network or Gateway Load Balancer on one subnet is still created. SetSubnets with one subnet and two subnets in one Availability Zone keep their InvalidConfigurationRequest answers. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(elbv2): cover a one-subnet ALB replacement Review follow-ups: - CloudFormationElbV2ReplacementIntegrationTest renames an Application Load Balancer onto one subnet: the update rolls back with CreateLoadBalancer's ValidationError, no balancer gets the new name, and the one it was to replace keeps both subnets. - ElbV2CfnProvisioner's Javadoc no longer says a blank SubnetId is refused as an unknown subnet, since an Application Load Balancer with only that mapping now gets the subnet count error first. - ElbV2ServiceTest says why its one-subnet test stubs a lookup that it then expects never to happen. - Ec2DescribeSubnetsNotFoundTest says the missing subnet is sent alongside an existing one, rather than that its position matters. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(elbv2): give the one-subnet NLB and GWLB test its own order Review follow-up: the test createLoadBalancerOnOneSubnetIsAllowedForNetworkAndGatewayLoadBalancers shared @Order(12) with createLoadBalancerWithOneSubnetIsAValidationError, so JUnit ran the two in no defined order. It now runs at @Order(78), after the other load balancer subnet tests. Neither test depends on the other: each uses its own load balancer names, and the network and gateway one deletes the balancers it creates. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(elbv2): move the one-subnet NLB and GWLB test to order 79 The draft #6100 adds setSubnetsWithNeitherSubnetsNorSubnetMappingsIsRefused at @Order(78) in the same class, and the two branches merge without a conflict, so whichever lands second would bring back a shared order. 79 is unused on main and on both branches; no other order changes. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> --------- Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
This commit is contained in:
1 parent
73e890dbc7
commit
61a42591a9
9 files changed
+219
-24
No files matched your search
+1
-1
@@ -216,7 +216,7 @@ public class ElbV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
* as one an Fn::If drops, does not count. {@code SubnetId} is required in a mapping, so one without it
|
||||
* fails the resource before anything is created or moved, with the error the resource schema gives.
|
||||
* A blank one counts as a mapping and, with no {@code Subnets}, is passed on as given for ELBv2 to
|
||||
* refuse as an unknown subnet; dropping it would create or move the balancer without it.
|
||||
* refuse; dropping it would create or move the balancer without it.
|
||||
*/
|
||||
private static List<String> templateSubnets(JsonNode props, ProvisionContext ctx) {
|
||||
List<String> subnets = ctx.resolveStringList(props, "Subnets");
|
||||
|
||||
@@ -283,18 +283,22 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
|
||||
}
|
||||
|
||||
/**
|
||||
* Every load balancer type takes {@code Subnets} or {@code SubnetMappings}, so a request with
|
||||
* neither is refused before anything is created, with the message AWS gives an Application or a
|
||||
* Network Load Balancer. A Gateway Load Balancer, which takes subnets the way a Network Load
|
||||
* Balancer does, gets the Network one. This runs after the duplicate-name check, because a
|
||||
* CloudFormation stack update finds the balancer it keeps through DuplicateLoadBalancerName,
|
||||
* whatever subnets its template names.
|
||||
* Every load balancer type takes {@code Subnets} or {@code SubnetMappings}, and an Application Load
|
||||
* Balancer takes at least two, so a request with fewer is refused before anything is created, with
|
||||
* the message AWS gives an Application or a Network Load Balancer. A Gateway Load Balancer, which
|
||||
* takes subnets the way a Network Load Balancer does, gets the Network one. AWS counts before it
|
||||
* looks a subnet up, so one subnet that does not exist gets this error too, not SubnetNotFound.
|
||||
* This runs after the duplicate-name check, because a CloudFormation stack update finds the
|
||||
* balancer it keeps through DuplicateLoadBalancerName, whatever subnets its template names.
|
||||
*/
|
||||
private static void requireSubnets(String lbType, List<String> subnets) {
|
||||
if (subnets == null || subnets.isEmpty()) {
|
||||
throw new AwsException("ValidationError", "application".equals(lbType)
|
||||
? "At least two subnets in two different Availability Zones must be specified"
|
||||
: "At least one subnet must be specified", 400);
|
||||
int count = subnets == null ? 0 : subnets.size();
|
||||
if ("application".equals(lbType) && count < 2) {
|
||||
throw new AwsException("ValidationError",
|
||||
"At least two subnets in two different Availability Zones must be specified", 400);
|
||||
}
|
||||
if (count == 0) {
|
||||
throw new AwsException("ValidationError", "At least one subnet must be specified", 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user