Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(ec2): apply availability-zone filter in DescribeInstances (#2543)

Leandro-ft3bdcd5b84fb2
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
index c54cab6468..8d94b30a83 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
@@ -5096,6 +5096,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
case "instance-type" -> matchesValue(values, inst.getInstanceType());
case "vpc-id" -> matchesValue(values, inst.getVpcId());
case "subnet-id" -> matchesValue(values, inst.getSubnetId());
+ case "availabilityZone", "availability-zone" -> inst.getPlacement() != null
+ && matchesValue(values, inst.getPlacement().getAvailabilityZone());
default -> true;
};
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java
index a93aa691f9..6e76716fc0 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java
@@ -1162,6 +1162,100 @@ class Ec2IntegrationTest {
.body("DescribeSubnetsResponse.subnetSet.item.cidrBlock", equalTo("10.10.1.0/24"));
}
+ @Test
+ @Order(24)
+ void describeInstancesByAvailabilityZoneFilter() {
+ String isolatedVpcId = given()
+ .formParam("Action", "CreateVpc")
+ .formParam("CidrBlock", "10.11.0.0/16")
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().path("CreateVpcResponse.vpc.vpcId");
+
+ String subnetA = given()
+ .formParam("Action", "CreateSubnet")
+ .formParam("VpcId", isolatedVpcId)
+ .formParam("CidrBlock", "10.11.1.0/24")
+ .formParam("AvailabilityZone", "us-east-1a")
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().path("CreateSubnetResponse.subnet.subnetId");
+
+ String subnetB = given()
+ .formParam("Action", "CreateSubnet")
+ .formParam("VpcId", isolatedVpcId)
+ .formParam("CidrBlock", "10.11.2.0/24")
+ .formParam("AvailabilityZone", "us-east-1b")
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().path("CreateSubnetResponse.subnet.subnetId");
+
+ String sgId = given()
+ .formParam("Action", "CreateSecurityGroup")
+ .formParam("GroupName", "az-filter-test-sg")
+ .formParam("GroupDescription", "AZ filter test")
+ .formParam("VpcId", isolatedVpcId)
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().path("CreateSecurityGroupResponse.groupId");
+
+ String instanceA = given()
+ .formParam("Action", "RunInstances")
+ .formParam("ImageId", "ami-0abcdef1234567890")
+ .formParam("InstanceType", "t2.micro")
+ .formParam("MinCount", "1")
+ .formParam("MaxCount", "1")
+ .formParam("SubnetId", subnetA)
+ .formParam("SecurityGroupId.1", sgId)
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().path("RunInstancesResponse.instancesSet.item.instanceId");
+
+ given()
+ .formParam("Action", "RunInstances")
+ .formParam("ImageId", "ami-0abcdef1234567890")
+ .formParam("InstanceType", "t2.micro")
+ .formParam("MinCount", "1")
+ .formParam("MaxCount", "1")
+ .formParam("SubnetId", subnetB)
+ .formParam("SecurityGroupId.1", sgId)
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .formParam("Action", "DescribeInstances")
+ .formParam("Filter.1.Name", "vpc-id")
+ .formParam("Filter.1.Value.1", isolatedVpcId)
+ .formParam("Filter.2.Name", "availability-zone")
+ .formParam("Filter.2.Value.1", "us-east-1a")
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.instanceId", equalTo(instanceA))
+ .body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.placement.availabilityZone",
+ equalTo("us-east-1a"));
+ }
+
@Test
@Order(21)
void createSubnetHasAssignIpv6AddressOnCreation() {