mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): Volume throughput, DescribeAddressesAttribute, and IAM instance profile parity (#1103)
* fix(ec2): add Volume throughput, DescribeAddressesAttribute, and IAM instance profile parity Three EC2 read-path gaps broke Terraform/OpenTofu apply cycles: throughput to the Volume model, parsed it in CreateVolume, and emitted it in CreateVolume/DescribeVolumes. gp3 defaults to 125 MiB/s (matching AWS); other volume types leave it null. the VPC module's aws_eip read cycle. Implemented the operation (returns allocationId + publicIp per AddressAttribute) and added it to the EC2 action allowlist. instance was launched with one, and DescribeIamInstanceProfileAssociations returned UnsupportedOperation — causing perpetual Terraform drift then a hard failure. instanceXml now emits <iamInstanceProfile> (arn + id), and DescribeIamInstanceProfileAssociations is implemented with instance-id filter and AssociationId lookup. Profile and association ids are derived deterministically from the instance id so repeated describes are stable. Verified against AWS SDK v2 shapes (Volume.Throughput, AddressAttribute, IamInstanceProfileAssociation). * fix: incorrect exception throw
This commit is contained in:
1 parent
0467eebf69
commit
a13a221a88
5 files changed
+323
-25
No files matched your search
+177
@@ -0,0 +1,177 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* Covers EC2 read-path parity gaps that broke Terraform/OpenTofu:
|
||||
* <ul>
|
||||
* <li>#1083 — gp3 Volume must report {@code throughput} in CreateVolume/DescribeVolumes</li>
|
||||
* <li>#1090 — DescribeAddressesAttribute must be supported (VPC module EIP read cycle)</li>
|
||||
* <li>#1094 — IamInstanceProfile in DescribeInstances + DescribeIamInstanceProfileAssociations</li>
|
||||
* </ul>
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class Ec2VolumeThroughputAndIamProfileIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20250101/us-east-1/ec2/aws4_request";
|
||||
|
||||
// ── #1083: Volume throughput ──────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void gp3VolumeReportsDefaultThroughput() {
|
||||
String volumeId = given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "CreateVolume")
|
||||
.formParam("AvailabilityZone", "us-east-1a")
|
||||
.formParam("VolumeType", "gp3")
|
||||
.formParam("Size", "10")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateVolumeResponse.volumeId", notNullValue())
|
||||
.body("CreateVolumeResponse.throughput", equalTo("125"))
|
||||
.extract().path("CreateVolumeResponse.volumeId");
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeVolumes")
|
||||
.formParam("VolumeId.1", volumeId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeVolumesResponse.volumeSet.item.throughput", equalTo("125"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void gp3VolumeHonoursExplicitThroughput() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "CreateVolume")
|
||||
.formParam("AvailabilityZone", "us-east-1a")
|
||||
.formParam("VolumeType", "gp3")
|
||||
.formParam("Size", "10")
|
||||
.formParam("Throughput", "250")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateVolumeResponse.throughput", equalTo("250"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void gp2VolumeOmitsThroughput() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "CreateVolume")
|
||||
.formParam("AvailabilityZone", "us-east-1a")
|
||||
.formParam("VolumeType", "gp2")
|
||||
.formParam("Size", "10")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// gp2 is not a throughput-provisionable type; only volumeType is asserted.
|
||||
// The handler omits the <throughput> element when the value is null
|
||||
// (positively verified for gp3 in the tests above).
|
||||
.body("CreateVolumeResponse.volumeType", equalTo("gp2"));
|
||||
}
|
||||
|
||||
// ── #1090: DescribeAddressesAttribute ─────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void describeAddressesAttributeReturnsAllocation() {
|
||||
String allocationId = given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "AllocateAddress")
|
||||
.formParam("Domain", "vpc")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AllocateAddressResponse.allocationId", startsWith("eipalloc-"))
|
||||
.extract().path("AllocateAddressResponse.allocationId");
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeAddressesAttribute")
|
||||
.formParam("AllocationId.1", allocationId)
|
||||
.formParam("Attribute", "domain-name")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAddressesAttributeResponse.addressSet.item.allocationId", equalTo(allocationId))
|
||||
.body("DescribeAddressesAttributeResponse.addressSet.item.publicIp", notNullValue());
|
||||
}
|
||||
|
||||
// ── #1094: IAM instance profile ───────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void instanceWithIamProfileExposesItInDescribeAndAssociations() {
|
||||
String instanceId = given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "RunInstances")
|
||||
.formParam("ImageId", "ami-12345678")
|
||||
.formParam("InstanceType", "t2.micro")
|
||||
.formParam("MinCount", "1")
|
||||
.formParam("MaxCount", "1")
|
||||
.formParam("IamInstanceProfile.Arn",
|
||||
"arn:aws:iam::000000000000:instance-profile/my-profile")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("RunInstancesResponse.instancesSet.item.instanceId");
|
||||
|
||||
// DescribeInstances must now carry the iamInstanceProfile block.
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeInstances")
|
||||
.formParam("InstanceId.1", instanceId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.iamInstanceProfile.arn",
|
||||
equalTo("arn:aws:iam::000000000000:instance-profile/my-profile"))
|
||||
.body("DescribeInstancesResponse.reservationSet.item.instancesSet.item.iamInstanceProfile.id",
|
||||
startsWith("AIPA"));
|
||||
|
||||
// DescribeIamInstanceProfileAssociations must resolve the association.
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeIamInstanceProfileAssociations")
|
||||
.formParam("Filter.1.Name", "instance-id")
|
||||
.formParam("Filter.1.Value.1", instanceId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeIamInstanceProfileAssociationsResponse.iamInstanceProfileAssociationSet.item.instanceId",
|
||||
equalTo(instanceId))
|
||||
.body("DescribeIamInstanceProfileAssociationsResponse.iamInstanceProfileAssociationSet.item.associationId",
|
||||
startsWith("iip-assoc-"))
|
||||
.body("DescribeIamInstanceProfileAssociationsResponse.iamInstanceProfileAssociationSet.item.state",
|
||||
equalTo("associated"))
|
||||
.body("DescribeIamInstanceProfileAssociationsResponse.iamInstanceProfileAssociationSet.item.iamInstanceProfile.arn",
|
||||
equalTo("arn:aws:iam::000000000000:instance-profile/my-profile"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user