fix(ec2): nest cidrBlockState in AssociateVpcCidrBlock response (#3243)

AssociateVpcCidrBlock returned cidrBlockState as a bare string
instead of the nested <state> element that DescribeVpcs already
returns for the same association. terraform-provider-aws's SDK
waiter for aws_vpc_ipv4_cidr_block_association parses the nested
shape, so it never observed a valid state and polled DescribeVpcs
until giving up, hanging `terraform apply` on any
secondary_cidr_blocks entry.

Fixes #3241
This commit is contained in:
Angel Abad authored and GitHub committed 2026-09-08 23:26:42 -05:00
1 parent eb3a6b23ef
commit 496b376da1
2 files changed
+66 -1

No files matched your search

@@ -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());
@@ -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 <cidrBlockState>associated</cidrBlockState>}) instead of the nested shape the real API
* uses ({@code <cidrBlockState><state>associated</state></cidrBlockState>}), 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"));
}
}