diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java index ca723581d4..62614711e4 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java @@ -2632,7 +2632,7 @@ public class Ec2QueryHandler { .start("cidrBlockAssociation") .elem("associationId", assoc.getAssociationId()) .elem("cidrBlock", assoc.getCidrBlock()) - .elem("cidrBlockState", assoc.getCidrBlockState()) + .start("cidrBlockState").elem("state", assoc.getCidrBlockState()).end("cidrBlockState") .end("cidrBlockAssociation") .end("AssociateVpcCidrBlockResponse"); return xmlResponse(xml.build()); diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2VpcCidrBlockAssociationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2VpcCidrBlockAssociationIntegrationTest.java new file mode 100644 index 0000000000..fbd8e860b1 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2VpcCidrBlockAssociationIntegrationTest.java @@ -0,0 +1,65 @@ +package io.github.hectorvent.floci.services.ec2; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +/** + * AssociateVpcCidrBlock returned cidrBlockState as a bare string + * ({@code associated}) instead of the nested shape the real API + * uses ({@code associated}), the same shape + * DescribeVpcs already returned for the identical association. The AWS SDK waiter that + * terraform-provider-aws uses for aws_vpc_ipv4_cidr_block_association parses the nested form, so + * it never saw a valid state and polled DescribeVpcs until it gave up, hanging `terraform apply` + * on any secondary_cidr_blocks entry. + */ +@QuarkusTest +class Ec2VpcCidrBlockAssociationIntegrationTest { + + private static final String AUTH_HEADER = + "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request"; + + @Test + void associateVpcCidrBlockReturnsNestedCidrBlockState() { + String vpcId = given() + .formParam("Action", "CreateVpc") + .formParam("CidrBlock", "10.94.0.0/24") + .header("Authorization", AUTH_HEADER) + .when() + .post("/") + .then() + .statusCode(200) + .extract().path("CreateVpcResponse.vpc.vpcId"); + + String associationId = given() + .formParam("Action", "AssociateVpcCidrBlock") + .formParam("VpcId", vpcId) + .formParam("CidrBlock", "10.95.0.0/24") + .header("Authorization", AUTH_HEADER) + .when() + .post("/") + .then() + .statusCode(200) + .body("AssociateVpcCidrBlockResponse.cidrBlockAssociation.cidrBlock", equalTo("10.95.0.0/24")) + // The regression: this must be the nested element, not a bare string value. + .body("AssociateVpcCidrBlockResponse.cidrBlockAssociation.cidrBlockState.state", + equalTo("associated")) + .extract().path("AssociateVpcCidrBlockResponse.cidrBlockAssociation.associationId"); + + // Same association, read back through DescribeVpcs, must agree on both shape and state. + given() + .formParam("Action", "DescribeVpcs") + .formParam("VpcId.1", vpcId) + .header("Authorization", AUTH_HEADER) + .when() + .post("/") + .then() + .statusCode(200) + .body("DescribeVpcsResponse.vpcSet.item.cidrBlockAssociationSet.item.find { " + + "it.associationId == '" + associationId + "' }.cidrBlockState.state", + equalTo("associated")); + } +}