Reputation: 609
I have an existing VPC with private/public subnets (created with the CDK) and an existing Transient Gateway (created manually) that is not in pending status. I am now trying to modify my stack to create a VPC Transit Gateway Attachment but my code is not finding the Transit Gateway. Here is the code:
// create a VPC attachment to the transit gateway
var transitGatewayAttachment = new CfnTransitGatewayAttachment(this, "TransitGatewayAttachment", new CfnTransitGatewayAttachmentProps
{
VpcId = Vpc.VpcId,
TransitGatewayId = "tgw-xxxxxx",
SubnetIds = Vpc.PrivateSubnets.Select(s => s.SubnetId).ToArray()
});
CDK returns the an error that the Transit Gateway does not exist. So does CloudFormation. I have double and tripple-checked the tgw id so I am buffled as to what the problem might be.
Upvotes: 0
Views: 675
Reputation: 609
Actually the problem was a delay between the attachment being created and it being available for consumption by my route table modifications. So I was able to create the attachment OK (above code is fine) but was failing routing to it from private subnets with the following code. Shown is the change that made it possible.
var index = 0;
Vpc.PrivateSubnets.ToList().ForEach(s =>
{
var route = new CfnRoute(this, $"TgwRoute{index}", new CfnRouteProps
{
DestinationCidrBlock = "xxx.xxx.xxx.xxx/xx",
RouteTableId = s.RouteTable.RouteTableId,
TransitGatewayId = "tgw-xxxxxx"
});
route.AddDependsOn(transitGatewayAttachment); // *** <--- *** This adds a dependency on TGW
index++;
});
Upvotes: 1