diff --git a/docs/services/ec2.md b/docs/services/ec2.md
index 2f08492f26..77239804e3 100644
--- a/docs/services/ec2.md
+++ b/docs/services/ec2.md
@@ -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
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 cb33f79b30..5f0ea6215d 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
@@ -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());
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java
index eeabee754e..69be78621d 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java
@@ -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("" + attachment + ""));
+ assertThat(body, containsString("vpc"));
+ assertThat(body, containsString("enabled"));
+
+ 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("" + attachedVpc + ""));
+
+ 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)));
+ }
}