fix(ec2): propagate transit gateway attachments to the default propagation route table (#7060)

* fix(ec2): propagate transit gateway attachments to the default propagation route table

* refactor(ec2): build transit gateway route table propagations in one helper

The default-propagation path in storeNewAttachment and
enableTransitGatewayRouteTablePropagation built the same propagation
record field for field. Both now call storePropagation.

* test(ec2): assert the resource id of a default-created propagation

The create-site VPC id argument to the propagation helper was not checked
by any test; only the resource type was.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-31 10:07:01 -04:00
1 parent b3dad93daf
commit 3b4a2ec14d
3 files changed
+132 -11

No files matched your search

+2
View File
@@ -720,6 +720,8 @@ returns `Resource.AlreadyAssociated` rather than moving it — disassociate firs
recorded on the attachment itself, which is why `GetTransitGatewayRouteTableAssociations` reports
the attachment's VPC as the associated resource.
A VPC attachment is propagated into the gateway's default propagation route table on creation when the gateway has `DefaultRouteTablePropagation` enabled, and leaves it when the attachment is deleted.
Propagation is separate: one attachment may propagate into several route tables. Enabling twice
returns `TransitGatewayRouteTablePropagation.Duplicate`. Unlike association, which reports
`associating` and `disassociating`, propagation reports the settled `enabled` or `disabled` at
@@ -2715,9 +2715,28 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
putTags(region, attachmentId, new ArrayList<>(attachmentTags));
}
transitGatewayVpcAttachments.put(key(region, attachmentId), attachment);
String propagationTableId = gateway.getOptions().getPropagationDefaultRouteTableId();
if ("enable".equals(gateway.getOptions().getDefaultRouteTablePropagation()) && propagationTableId != null) {
storePropagation(region, propagationTableId, attachmentId, vpcId);
}
return attachment;
}
private TransitGatewayRouteTablePropagation storePropagation(
String region, String routeTableId, String attachmentId, String vpcId) {
TransitGatewayRouteTablePropagation propagation = new TransitGatewayRouteTablePropagation();
propagation.setTransitGatewayRouteTableId(routeTableId);
propagation.setTransitGatewayAttachmentId(attachmentId);
propagation.setResourceId(vpcId);
propagation.setResourceType("vpc");
// Verified live: propagation reports the settled state at once, where association
// reports associating first.
propagation.setState("enabled");
propagation.setRegion(region);
transitGatewayPropagations.put(propagationKey(region, routeTableId, attachmentId), propagation);
return propagation;
}
/**
* One region-wide monitor for every operation that creates an attachment, removes one, or
* removes something an attachment depends on. Held outermost wherever a gateway lock is also
@@ -3301,17 +3320,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
throw new AwsException("TransitGatewayRouteTablePropagation.Duplicate", "Propagation "
+ attachmentId + " already exists in Transit Gateway Route Table " + routeTableId + ".", 400);
}
TransitGatewayRouteTablePropagation propagation = new TransitGatewayRouteTablePropagation();
propagation.setTransitGatewayRouteTableId(routeTableId);
propagation.setTransitGatewayAttachmentId(attachmentId);
propagation.setResourceId(attachment.getVpcId());
propagation.setResourceType("vpc");
// Verified live: propagation reports the settled state at once, where association
// reports associating first.
propagation.setState("enabled");
propagation.setRegion(region);
transitGatewayPropagations.put(propagationKey(region, routeTableId, attachmentId), propagation);
return propagation;
return storePropagation(region, routeTableId, attachmentId, attachment.getVpcId());
}
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.ec2;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -244,4 +245,113 @@ class Ec2TransitGatewayVpcAttachmentIntegrationTest {
.then().statusCode(400)
.body("Response.Errors.Error.Code", equalTo("InvalidTransitGatewayConnectID.NotFound"));
}
private String createGateway(String propagation) {
RequestSpecification request = given()
.formParam("Action", "CreateTransitGateway")
.header("Authorization", AUTH_HEADER);
if (propagation != null) {
request = request.formParam("Options.DefaultRouteTablePropagation", propagation);
}
return request.when().post("/").then().statusCode(200)
.extract().path("CreateTransitGatewayResponse.transitGateway.transitGatewayId");
}
private String propagationTableOf(String gatewayId) {
return given()
.formParam("Action", "DescribeTransitGateways")
.formParam("TransitGatewayIds.1", gatewayId)
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().path("DescribeTransitGatewaysResponse.transitGatewaySet.item.options"
+ ".propagationDefaultRouteTableId");
}
private String attach(String gatewayId) {
String vpc = given()
.formParam("Action", "CreateVpc")
.formParam("CidrBlock", "10.81.0.0/16")
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().path("CreateVpcResponse.vpc.vpcId");
String subnet = given()
.formParam("Action", "CreateSubnet")
.formParam("VpcId", vpc)
.formParam("CidrBlock", "10.81.1.0/24")
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().path("CreateSubnetResponse.subnet.subnetId");
return given()
.formParam("Action", "CreateTransitGatewayVpcAttachment")
.formParam("TransitGatewayId", gatewayId)
.formParam("VpcId", vpc)
.formParam("SubnetIds.1", subnet)
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().path("CreateTransitGatewayVpcAttachmentResponse.transitGatewayVpcAttachment"
+ ".transitGatewayAttachmentId");
}
private String propagationsOf(String tableId) {
return given()
.formParam("Action", "GetTransitGatewayRouteTablePropagations")
.formParam("TransitGatewayRouteTableId", tableId)
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().asString();
}
@Test
@Order(9)
void attachmentPropagatesIntoTheDefaultTableAndLeavesItOnDelete() {
String gateway = createGateway(null);
String table = propagationTableOf(gateway);
String attachment = attach(gateway);
String body = propagationsOf(table);
assertThat(body, containsString("<transitGatewayAttachmentId>" + attachment + "</transitGatewayAttachmentId>"));
assertThat(body, containsString("<resourceType>vpc</resourceType>"));
assertThat(body, containsString("<state>enabled</state>"));
String attachedVpc = given()
.formParam("Action", "DescribeTransitGatewayVpcAttachments")
.formParam("TransitGatewayAttachmentIds.1", attachment)
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().path("DescribeTransitGatewayVpcAttachmentsResponse.transitGatewayVpcAttachments.item.vpcId");
assertThat(body, containsString("<resourceId>" + attachedVpc + "</resourceId>"));
given()
.formParam("Action", "DeleteTransitGatewayVpcAttachment")
.formParam("TransitGatewayAttachmentId", attachment)
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200);
assertThat(propagationsOf(table), not(containsString(attachment)));
}
@Test
@Order(10)
void attachmentDoesNotPropagateWhenGatewayDisablesDefaultPropagation() {
String gateway = createGateway("disable");
String attachment = attach(gateway);
String associationTable = given()
.formParam("Action", "DescribeTransitGateways")
.formParam("TransitGatewayIds.1", gateway)
.header("Authorization", AUTH_HEADER)
.when().post("/")
.then().statusCode(200)
.extract().path("DescribeTransitGatewaysResponse.transitGatewaySet.item.options"
+ ".associationDefaultRouteTableId");
// Regression guard for the enable check: the default association table must not gain a propagation.
assertThat(propagationsOf(associationTable), not(containsString(attachment)));
}
}