feat(ec2): support transit gateway peering attachments (#5122)

* feat(ec2): support transit gateway peering attachments

Add CreateTransitGatewayPeeringAttachment, DescribeTransitGatewayPeeringAttachments,
AcceptTransitGatewayPeeringAttachment and DeleteTransitGatewayPeeringAttachment, the
calls the Terraform provider's aws_ec2_transit_gateway_peering_attachment and
_accepter resources make. Previously each answered UnsupportedOperation.

An attachment is created in pendingAcceptance and moves to available when accepted
from the accepter's region. One attachment id serves both sides, so a cross-region
peering is visible from either region and the transit-gateway-id filter matches either
side's gateway, which is how the accepter finds it. Tags come from the shared tag
store, so CreateTags on the accepter side round-trips through describe.

* style(ec2): order the TransitGatewayPeeringAttachment import

* fix(ec2): hold peered transit gateways and accept peerings only as the peer

DeleteTransitGateway now refuses with IncorrectState while a non-deleted
peering attachment names the gateway at either end, as it already does for
VPC attachments; creation takes the same topology lock so neither lands in
between.

A peering is stored under the requester's account, so lookups search every
account's partition and admit only the two parties, as VPC peering does.
Accept requires the caller to be the accepter's account in the accepter's
region, so a requester can no longer accept its own cross-account request,
and the peer account can now see and accept it. The local-owner-id and
remote-owner-id filters are relative to the viewer's side.

* test(ec2): cover transit gateway peering attachments in the AWS CLI compatibility suite

* style(ec2): drop em dashes from the peering attachment comments

* refactor(ec2): make the peering attachment store final and pass it through the constructor

The StorageFactory constructor now hands the factory-backed store to the
terminal constructor, and the hermetic overload passes an InMemoryStorage,
the same way the other EC2 stores are wired.

* fix(ec2): clear both sides' tags when a cross-account peering attachment is deleted

Tags are per account: each party to a peering sees the tags its own account
set. Deleting the attachment cleared only the caller's, so the other
party's tags outlived it.

* fix(ec2): let a pending peering's accepter delete its transit gateway

Anyone can name any gateway as their peer, so a peering that has not been
accepted no longer holds the accepter's gateway. Deleting that gateway
declines the peering, leaving it rejected. Accepted peerings still hold
both ends, and a pending one still holds its requester's.

* fix(ec2): accept a transit gateway peering only for a gateway the accepter owns

The peer gateway is recorded unresolved at create, so an account could name
another account's gateway as the peer with its own account as PeerAccountId,
accept it, and pin that gateway against its real owner's DeleteTransitGateway.
Accepting now requires the peer gateway to exist in the caller's account and
region, the same lookup create makes for the requester's gateway.

* fix(ec2): route transit gateway peering actions to ec2 without a credential scope
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-08 19:59:39 -04:00
1 parent dc41417e79
commit e22bd2c59a
7 files changed
+1026 -5

No files matched your search

@@ -205,6 +205,8 @@ public class AwsQueryController {
"CreateNetworkAclEntry", "ReplaceNetworkAclEntry", "DeleteNetworkAclEntry",
"ReplaceNetworkAclAssociation",
"CreateNatGateway", "DescribeNatGateways", "DeleteNatGateway",
"CreateTransitGatewayPeeringAttachment", "AcceptTransitGatewayPeeringAttachment",
"DeleteTransitGatewayPeeringAttachment", "DescribeTransitGatewayPeeringAttachments",
"CreateCapacityReservation", "DescribeCapacityReservations",
"ModifyCapacityReservation", "CancelCapacityReservation",
"AllocateAddress", "AssociateAddress", "DisassociateAddress", "ReleaseAddress", "DescribeAddresses",
@@ -132,6 +132,16 @@ public class Ec2QueryHandler {
handleModifyTransitGatewayVpcAttachment(params, region);
case "DeleteTransitGatewayVpcAttachment" ->
handleDeleteTransitGatewayVpcAttachment(params, region);
case "CreateTransitGatewayPeeringAttachment" ->
handleCreateTransitGatewayPeeringAttachment(params, region);
case "DescribeTransitGatewayPeeringAttachments" ->
handleDescribeTransitGatewayPeeringAttachments(params, region);
case "AcceptTransitGatewayPeeringAttachment" -> peeringAttachmentResponse(
"AcceptTransitGatewayPeeringAttachmentResponse", service.acceptTransitGatewayPeeringAttachment(
region, params.getFirst("TransitGatewayAttachmentId")));
case "DeleteTransitGatewayPeeringAttachment" -> peeringAttachmentResponse(
"DeleteTransitGatewayPeeringAttachmentResponse", service.deleteTransitGatewayPeeringAttachment(
region, params.getFirst("TransitGatewayAttachmentId")));
// Transit Gateway route tables, associations, propagations and routes
case "CreateTransitGatewayRouteTable" -> handleCreateTransitGatewayRouteTable(params, region);
case "DescribeTransitGatewayRouteTables" ->
@@ -2507,6 +2517,63 @@ public class Ec2QueryHandler {
return xmlResponse(xml.build());
}
private Response handleCreateTransitGatewayPeeringAttachment(MultivaluedMap<String, String> p, String region) {
return peeringAttachmentResponse("CreateTransitGatewayPeeringAttachmentResponse",
service.createTransitGatewayPeeringAttachment(region,
p.getFirst("TransitGatewayId"),
p.getFirst("PeerTransitGatewayId"),
p.getFirst("PeerAccountId"),
p.getFirst("PeerRegion"),
p.getFirst("Options.DynamicRouting"),
parseTagsForResource(p, "transit-gateway-attachment")));
}
private Response handleDescribeTransitGatewayPeeringAttachments(MultivaluedMap<String, String> p,
String region) {
XmlBuilder xml = new XmlBuilder()
.start("DescribeTransitGatewayPeeringAttachmentsResponse", AwsNamespaces.EC2)
.elem("requestId", UUID.randomUUID().toString())
.start("transitGatewayPeeringAttachments");
for (TransitGatewayPeeringAttachment attachment : service.describeTransitGatewayPeeringAttachments(
region, getList(p, "TransitGatewayAttachmentIds"), getFilters(p))) {
xml.start("item").raw(peeringAttachmentXml(attachment)).end("item");
}
xml.end("transitGatewayPeeringAttachments").end("DescribeTransitGatewayPeeringAttachmentsResponse");
return xmlResponse(xml.build());
}
/** Create, accept and delete all answer with the attachment under the same member name. */
private Response peeringAttachmentResponse(String responseName, TransitGatewayPeeringAttachment attachment) {
XmlBuilder xml = new XmlBuilder()
.start(responseName, AwsNamespaces.EC2)
.elem("requestId", UUID.randomUUID().toString())
.start("transitGatewayPeeringAttachment").raw(peeringAttachmentXml(attachment))
.end("transitGatewayPeeringAttachment")
.end(responseName);
return xmlResponse(xml.build());
}
private String peeringAttachmentXml(TransitGatewayPeeringAttachment attachment) {
XmlBuilder xml = new XmlBuilder()
.elem("transitGatewayAttachmentId", attachment.getTransitGatewayAttachmentId());
List<Map.Entry<String, TransitGatewayPeeringAttachment.TgwInfo>> sides = List.of(
Map.entry("requesterTgwInfo", attachment.getRequesterTgwInfo()),
Map.entry("accepterTgwInfo", attachment.getAccepterTgwInfo()));
for (Map.Entry<String, TransitGatewayPeeringAttachment.TgwInfo> side : sides) {
xml.start(side.getKey())
.elem("transitGatewayId", side.getValue().getTransitGatewayId())
.elem("ownerId", side.getValue().getOwnerId())
.elem("region", side.getValue().getRegion())
.end(side.getKey());
}
return xml.start("options").elem("dynamicRouting", attachment.getDynamicRouting()).end("options")
.start("status").elem("code", attachment.getState()).end("status")
.elem("state", attachment.getState())
.elem("creationTime", attachment.getCreationTime())
.raw(tagSetXml(attachment.getTags()))
.build();
}
private TransitGatewayVpcAttachmentOptions parseVpcAttachmentOptions(MultivaluedMap<String, String> p) {
TransitGatewayVpcAttachmentOptions options = new TransitGatewayVpcAttachmentOptions();
options.setDnsSupport(p.getFirst("Options.DnsSupport"));
@@ -71,6 +71,7 @@ import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.ec2.model.Tag;
import io.github.hectorvent.floci.services.ec2.model.TransitGateway;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayOptions;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayPeeringAttachment;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRoute;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRouteTable;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRouteTablePropagation;
@@ -254,6 +255,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
private final StorageBackend<String, TransitGatewayVpcAttachment> transitGatewayVpcAttachments;
private final StorageBackend<String, TransitGatewayRouteTablePropagation> transitGatewayPropagations;
private final StorageBackend<String, TransitGatewayRoute> transitGatewayRoutes;
// Keyed by id alone: one attachment serves both regions of a cross-region peering.
private final StorageBackend<String, TransitGatewayPeeringAttachment> transitGatewayPeeringAttachments;
// Keyed by id alone, not region::id — see VpcPeeringConnection's class Javadoc.
private final StorageBackend<String, VpcPeeringConnection> vpcPeeringConnections;
// Standalone (non-primary) ENIs created via CreateNetworkInterface, see #floci-kt9.
@@ -493,7 +496,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
storageFactory.create("ec2", "ec2-volume-modifications.json",
new TypeReference<Map<String, VolumeModification>>() {}),
requestContextInstance, iamService, volumeBlockDeviceManager,
storageFactory.create("ec2", "ec2-hosts.json", new TypeReference<Map<String, Host>>() {}));
storageFactory.create("ec2", "ec2-hosts.json", new TypeReference<Map<String, Host>>() {}),
storageFactory.create("ec2", "ec2-transit-gateway-peering-attachments.json",
new TypeReference<Map<String, TransitGatewayPeeringAttachment>>() {}));
}
// Package-private for hermetic tests (pass in-memory or temp-dir-backed StorageBackends directly).
@@ -700,11 +705,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
transitGateways, transitGatewayRouteTables, transitGatewayVpcAttachments,
transitGatewayPropagations, transitGatewayRoutes, vpcPeeringConnections,
networkInterfaces, capacityReservations, volumeModifications,
requestContextInstance, iamService, volumeBlockDeviceManager, new InMemoryStorage<>());
requestContextInstance, iamService, volumeBlockDeviceManager, new InMemoryStorage<>(),
new InMemoryStorage<>());
}
// The terminal constructor. Dedicated Hosts ride on their own parameter so the shorter
// overloads above keep their arity for existing fixtures.
// The terminal constructor. Dedicated Hosts and transit gateway peering attachments ride on
// their own parameters so the shorter overloads above keep their arity for existing fixtures.
Ec2Service(EmulatorConfig config, Ec2ContainerManager containerManager,
Ec2PortForwardManager portForwardManager,
AmiImageResolver amiImageResolver, Ec2ImageCatalog imageCatalog,
@@ -740,8 +746,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
jakarta.enterprise.inject.Instance<RequestContext> requestContextInstance,
IamService iamService,
Ec2VolumeBlockDeviceManager volumeBlockDeviceManager,
StorageBackend<String, Host> hosts) {
StorageBackend<String, Host> hosts,
StorageBackend<String, TransitGatewayPeeringAttachment> transitGatewayPeeringAttachments) {
this.hosts = hosts;
this.transitGatewayPeeringAttachments = transitGatewayPeeringAttachments;
this.iamService = iamService;
this.volumeBlockDeviceManager = volumeBlockDeviceManager;
this.defaultAccountId = config.defaultAccountId();
@@ -2050,6 +2058,25 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
throw new AwsException("IncorrectState", transitGatewayId
+ " has non-deleted VPC Attachments: " + String.join(", ", attached) + ".", 400);
}
// An accepted peering holds the gateway at either end; a pending one only its requester's.
// The accepter never agreed to a pending peering, and anyone can name any gateway as the
// peer, so it must not pin that gateway: its owner deleting it declines the peering.
List<TransitGatewayPeeringAttachment> live = allPeeringAttachments().stream()
.filter(attachment -> !Set.of("deleted", "rejected").contains(attachment.getState()))
.toList();
List<String> peered = live.stream()
.filter(attachment -> isGateway(attachment.getRequesterTgwInfo(), region, transitGatewayId)
|| !"pendingAcceptance".equals(attachment.getState())
&& isGateway(attachment.getAccepterTgwInfo(), region, transitGatewayId))
.map(TransitGatewayPeeringAttachment::getTransitGatewayAttachmentId)
.toList();
if (!peered.isEmpty()) {
throw new AwsException("IncorrectState", transitGatewayId
+ " has non-deleted Peering Attachments: " + String.join(", ", peered) + ".", 400);
}
live.stream()
.filter(attachment -> isGateway(attachment.getAccepterTgwInfo(), region, transitGatewayId))
.forEach(attachment -> rejectPendingPeering(attachment.getTransitGatewayAttachmentId()));
transitGatewayRouteTables.scan(k -> true).stream()
.filter(routeTable -> region.equals(routeTable.getRegion()))
.filter(routeTable -> transitGatewayId.equals(routeTable.getTransitGatewayId()))
@@ -2337,6 +2364,211 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
}
// ─── Transit Gateway Peering Attachments ───────────────────────────────────
/**
* Requests a peering between a local transit gateway and a peer one. The peer gateway is not
* resolved: it may live in another account this store cannot see, and AWS settles that
* asynchronously. AWS passes through {@code initiatingRequest}; nothing is slow locally, so
* the attachment is created already waiting for the peer.
*/
public TransitGatewayPeeringAttachment createTransitGatewayPeeringAttachment(
String region, String transitGatewayId, String peerTransitGatewayId, String peerAccountId,
String peerRegion, String dynamicRouting, List<Tag> attachmentTags) {
for (String[] required : new String[][] {{"PeerTransitGatewayId", peerTransitGatewayId},
{"PeerAccountId", peerAccountId}, {"PeerRegion", peerRegion}}) {
if (!isSet(required[1])) {
throw new AwsException("MissingParameter",
"The request must contain the parameter " + required[0] + ".", 400);
}
}
// Under the lock DeleteTransitGateway checks peerings under, so neither lands in between.
synchronized (attachmentTopologyLock(region)) {
TransitGateway gateway = getRequiredTransitGateway(region, transitGatewayId);
TransitGatewayPeeringAttachment attachment = new TransitGatewayPeeringAttachment();
String attachmentId = "tgw-attach-" + randomHex(17);
attachment.setTransitGatewayAttachmentId(attachmentId);
attachment.setRequesterTgwInfo(new TransitGatewayPeeringAttachment.TgwInfo(
transitGatewayId, gateway.getOwnerId(), region));
attachment.setAccepterTgwInfo(new TransitGatewayPeeringAttachment.TgwInfo(
peerTransitGatewayId, peerAccountId, peerRegion));
attachment.setDynamicRouting(isSet(dynamicRouting) ? dynamicRouting : "disable");
attachment.setState("pendingAcceptance");
attachment.setCreationTime(ISO_FMT.format(Instant.now()));
transitGatewayPeeringAttachments.put(attachmentId, attachment);
if (attachmentTags != null && !attachmentTags.isEmpty()) {
tags.put(attachmentId, new ArrayList<>(attachmentTags));
}
return withStoredTags(attachment);
}
}
public List<TransitGatewayPeeringAttachment> describeTransitGatewayPeeringAttachments(
String region, List<String> attachmentIds, Map<String, List<String>> filters) {
attachmentIds.forEach(Ec2Service::requireWellFormedAttachmentId);
String account = callerAccountId();
List<TransitGatewayPeeringAttachment> visible = allPeeringAttachments().stream()
.filter(attachment -> isPartyTo(attachment, account, region))
.map(this::withStoredTags)
.toList();
for (String attachmentId : attachmentIds) {
if (visible.stream().noneMatch(a -> a.getTransitGatewayAttachmentId().equals(attachmentId))) {
throw peeringAttachmentNotFound(attachmentId);
}
}
return visible.stream()
.filter(a -> attachmentIds.isEmpty() || attachmentIds.contains(a.getTransitGatewayAttachmentId()))
.filter(a -> matchesFilters(a, filters, region))
.collect(Collectors.toList());
}
/**
* Only the accepter accepts (its account, in its region), and only while the attachment is
* still pending. A requester whose peer is another account cannot accept on the peer's behalf.
*/
public TransitGatewayPeeringAttachment acceptTransitGatewayPeeringAttachment(String region, String attachmentId) {
// The accepter's DeleteTransitGateway declines pending peerings under this region's lock.
synchronized (attachmentTopologyLock(region)) {
synchronized (lockFor(attachmentId)) {
OwnedPeeringAttachment owned = getRequiredPeeringAttachment(region, attachmentId);
TransitGatewayPeeringAttachment attachment = owned.attachment();
if (!isGatewayOf(attachment.getAccepterTgwInfo(), callerAccountId(), region)) {
throw peeringAttachmentNotFound(attachmentId);
}
if (!"pendingAcceptance".equals(attachment.getState())) {
throw new AwsException("IncorrectState", "tgw-attach " + attachmentId
+ " is in invalid state " + attachment.getState() + ".", 400);
}
// The peer gateway was recorded unresolved at create, so anyone could have named someone
// else's gateway with their own account as the peer. Accepting is where that is settled:
// the gateway has to be the caller's, the same lookup create makes for the requester's.
getRequiredTransitGateway(region, attachment.getAccepterTgwInfo().getTransitGatewayId());
attachment.setState("available");
savePeeringAttachment(owned);
return withStoredTags(attachment);
}
}
}
/** Re-read under the attachment's lock, so a concurrent delete or accept is not overwritten. */
private void rejectPendingPeering(String attachmentId) {
synchronized (lockFor(attachmentId)) {
findPeeringAttachment(attachmentId)
.filter(owned -> "pendingAcceptance".equals(owned.attachment().getState()))
.ifPresent(owned -> {
owned.attachment().setState("rejected");
savePeeringAttachment(owned);
});
}
}
private void savePeeringAttachment(OwnedPeeringAttachment owned) {
String attachmentId = owned.attachment().getTransitGatewayAttachmentId();
if (owned.storageAccountId() != null) {
peeringAttachmentsByAccount().putForAccount(owned.storageAccountId(), attachmentId, owned.attachment());
} else {
transitGatewayPeeringAttachments.put(attachmentId, owned.attachment());
}
}
/** Either side may delete. AWS reports {@code deleting} first; the settled state is returned. */
public TransitGatewayPeeringAttachment deleteTransitGatewayPeeringAttachment(String region, String attachmentId) {
synchronized (lockFor(attachmentId)) {
OwnedPeeringAttachment owned = getRequiredPeeringAttachment(region, attachmentId);
TransitGatewayPeeringAttachment attachment = withStoredTags(owned.attachment());
if (owned.storageAccountId() != null) {
peeringAttachmentsByAccount().deleteForAccount(owned.storageAccountId(), attachmentId);
} else {
transitGatewayPeeringAttachments.delete(attachmentId);
}
// Tags are per account, so each side keeps its own; both go with the attachment.
if (tags instanceof AccountAwareStorageBackend<?> tagsByAccount) {
tagsByAccount.deleteForAccount(attachment.getRequesterTgwInfo().getOwnerId(), attachmentId);
tagsByAccount.deleteForAccount(attachment.getAccepterTgwInfo().getOwnerId(), attachmentId);
} else {
tags.delete(attachmentId);
}
attachment.setState("deleted");
return attachment;
}
}
/** A peering attachment together with the account partition its storage entry lives under. */
private record OwnedPeeringAttachment(String storageAccountId, TransitGatewayPeeringAttachment attachment) {}
/**
* Stored under the requester's account, but the accepter may be another account, so lookups
* search every account's partition and then admit only the two parties, the same pattern
* {@link #allVpcPeeringConnections} uses.
*/
private OwnedPeeringAttachment getRequiredPeeringAttachment(String region, String attachmentId) {
if (!isSet(attachmentId)) {
throw new AwsException("MissingParameter",
"The request must contain the parameter TransitGatewayAttachmentId.", 400);
}
requireWellFormedAttachmentId(attachmentId);
return findPeeringAttachment(attachmentId)
.filter(owned -> isPartyTo(owned.attachment(), callerAccountId(), region))
.orElseThrow(() -> peeringAttachmentNotFound(attachmentId));
}
private Optional<OwnedPeeringAttachment> findPeeringAttachment(String attachmentId) {
AccountAwareStorageBackend<TransitGatewayPeeringAttachment> byAccount = peeringAttachmentsByAccount();
return byAccount != null
? byAccount.findAnyAccountEntry(attachmentId)
.map(entry -> new OwnedPeeringAttachment(entry.account(), entry.value()))
: transitGatewayPeeringAttachments.get(attachmentId)
.map(attachment -> new OwnedPeeringAttachment(null, attachment));
}
private List<TransitGatewayPeeringAttachment> allPeeringAttachments() {
AccountAwareStorageBackend<TransitGatewayPeeringAttachment> byAccount = peeringAttachmentsByAccount();
return byAccount != null ? byAccount.scanAllAccounts() : transitGatewayPeeringAttachments.scan(k -> true);
}
@SuppressWarnings("unchecked")
private AccountAwareStorageBackend<TransitGatewayPeeringAttachment> peeringAttachmentsByAccount() {
return transitGatewayPeeringAttachments instanceof AccountAwareStorageBackend<?> byAccount
? (AccountAwareStorageBackend<TransitGatewayPeeringAttachment>) byAccount : null;
}
private static boolean isPartyTo(TransitGatewayPeeringAttachment attachment, String account, String region) {
return isGatewayOf(attachment.getRequesterTgwInfo(), account, region)
|| isGatewayOf(attachment.getAccepterTgwInfo(), account, region);
}
/** Whether this end of a peering is the caller's: its account, seen from its region. */
private static boolean isGatewayOf(TransitGatewayPeeringAttachment.TgwInfo side, String account, String region) {
return account.equals(side.getOwnerId()) && region.equals(side.getRegion());
}
private static boolean isGateway(TransitGatewayPeeringAttachment.TgwInfo side, String region, String gatewayId) {
return region.equals(side.getRegion()) && gatewayId.equals(side.getTransitGatewayId());
}
/** The end the caller sees as local: the accepter's, when the caller is the accepter and not also the requester. */
private TransitGatewayPeeringAttachment.TgwInfo localSide(TransitGatewayPeeringAttachment attachment, String region) {
String account = callerAccountId();
return !isGatewayOf(attachment.getRequesterTgwInfo(), account, region)
&& isGatewayOf(attachment.getAccepterTgwInfo(), account, region)
? attachment.getAccepterTgwInfo() : attachment.getRequesterTgwInfo();
}
private TransitGatewayPeeringAttachment.TgwInfo remoteSide(TransitGatewayPeeringAttachment attachment, String region) {
return localSide(attachment, region) == attachment.getRequesterTgwInfo()
? attachment.getAccepterTgwInfo() : attachment.getRequesterTgwInfo();
}
private TransitGatewayPeeringAttachment withStoredTags(TransitGatewayPeeringAttachment attachment) {
attachment.setTags(new ArrayList<>(tags.get(attachment.getTransitGatewayAttachmentId()).orElse(List.of())));
return attachment;
}
private static AwsException peeringAttachmentNotFound(String attachmentId) {
return new AwsException("InvalidTransitGatewayAttachmentID.NotFound",
"Transit Gateway Attachment " + attachmentId + " was deleted or does not exist.", 400);
}
// ─── Transit Gateway Route Tables, Associations, Propagations and Routes ───
/**
@@ -9017,6 +9249,19 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
default -> true;
};
}
if (resource instanceof TransitGatewayPeeringAttachment attachment) {
return switch (filterName) {
case "transit-gateway-attachment-id" -> matchesValue(values, attachment.getTransitGatewayAttachmentId());
// Either side's gateway: the accepter looks its attachment up by its own gateway.
case "transit-gateway-id" -> matchesValue(values, attachment.getRequesterTgwInfo().getTransitGatewayId())
|| matchesValue(values, attachment.getAccepterTgwInfo().getTransitGatewayId());
// Local and remote are the viewer's: the accepter sees itself as local.
case "local-owner-id" -> matchesValue(values, localSide(attachment, region).getOwnerId());
case "remote-owner-id" -> matchesValue(values, remoteSide(attachment, region).getOwnerId());
case "state" -> matchesValue(values, attachment.getState());
default -> true;
};
}
if (resource instanceof TransitGatewayVpcAttachment attachment) {
return switch (filterName) {
case "transit-gateway-attachment-id" -> matchesValue(values, attachment.getTransitGatewayAttachmentId());
@@ -9295,6 +9540,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
if (resource instanceof TransitGateway gateway) return gateway.getTags();
if (resource instanceof TransitGatewayRouteTable routeTable) return routeTable.getTags();
if (resource instanceof TransitGatewayVpcAttachment attachment) return attachment.getTags();
if (resource instanceof TransitGatewayPeeringAttachment attachment) return attachment.getTags();
if (resource instanceof VpcPeeringConnection pcx) return pcx.getTags();
if (resource instanceof CapacityReservation cr) return cr.getTags();
if (resource instanceof Host host) {
@@ -0,0 +1,78 @@
package io.github.hectorvent.floci.services.ec2.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
import java.util.List;
/**
* A peering attachment between two transit gateways. One attachment id serves both sides, so a
* cross-region peering is visible from the requester's region and the accepter's alike.
*/
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class TransitGatewayPeeringAttachment {
private String transitGatewayAttachmentId;
private TgwInfo requesterTgwInfo = new TgwInfo();
private TgwInfo accepterTgwInfo = new TgwInfo();
private String dynamicRouting;
private String state;
private String creationTime;
/** Filled from the tag store on read; tags are not persisted on the record itself. */
@JsonIgnore
private List<Tag> tags = new ArrayList<>();
public TransitGatewayPeeringAttachment() {}
public String getTransitGatewayAttachmentId() { return transitGatewayAttachmentId; }
public void setTransitGatewayAttachmentId(String transitGatewayAttachmentId) {
this.transitGatewayAttachmentId = transitGatewayAttachmentId;
}
public TgwInfo getRequesterTgwInfo() { return requesterTgwInfo; }
public void setRequesterTgwInfo(TgwInfo requesterTgwInfo) { this.requesterTgwInfo = requesterTgwInfo; }
public TgwInfo getAccepterTgwInfo() { return accepterTgwInfo; }
public void setAccepterTgwInfo(TgwInfo accepterTgwInfo) { this.accepterTgwInfo = accepterTgwInfo; }
public String getDynamicRouting() { return dynamicRouting; }
public void setDynamicRouting(String dynamicRouting) { this.dynamicRouting = dynamicRouting; }
public String getState() { return state; }
public void setState(String state) { this.state = state; }
public String getCreationTime() { return creationTime; }
public void setCreationTime(String creationTime) { this.creationTime = creationTime; }
public List<Tag> getTags() { return tags; }
public void setTags(List<Tag> tags) { this.tags = tags; }
/** One side of the peering: the {@code PeeringTgwInfo} shape. */
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public static class TgwInfo {
private String transitGatewayId;
private String ownerId;
private String region;
public TgwInfo() {}
public TgwInfo(String transitGatewayId, String ownerId, String region) {
this.transitGatewayId = transitGatewayId;
this.ownerId = ownerId;
this.region = region;
}
public String getTransitGatewayId() { return transitGatewayId; }
public void setTransitGatewayId(String transitGatewayId) { this.transitGatewayId = transitGatewayId; }
public String getOwnerId() { return ownerId; }
public void setOwnerId(String ownerId) { this.ownerId = ownerId; }
public String getRegion() { return region; }
public void setRegion(String region) { this.region = region; }
}
}