mtkh
mtkh

Reputation: 41

TransitGatewayRouteTableId for default TransitGatewayRouteTable

I am using the following settings for creating a transit gateway through CloudFormation.

AutoAcceptSharedAttachments: disable
DefaultRouteTableAssociation: enable
DefaultRouteTablePropagation: enable

I want to know how can one get the "TransitGatewayRouteTableId" in this situation? It is a necessary property for creating a static route in the default transit gateway route table.

Type: AWS::EC2::TransitGatewayRoute
Properties: 
  Blackhole: Boolean
  DestinationCidrBlock: String
  TransitGatewayAttachmentId: String
  TransitGatewayRouteTableId: String

I have already tried the following !GetAtt intrinsic function but it doesn't work since it seems that the only return value for a transit gateway resource is the id https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgateway.html

TransitGatewayRouteTableId: !GetAtt TransitGateway.AssociationDefaultRouteTableId

Upvotes: 3

Views: 681

Answers (1)

b.b3rn4rd
b.b3rn4rd

Reputation: 8840

Thats an annoying limitation of the AWS::EC2::TransitGatewayRoute resource you will have to write a custom resource using a lambda function to retrieve AssociationDefaultRouteTableId, use the transit-gateway id value and pass it into custom resource lambda. If you're going to use python use describe-transit-gateways method https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_transit_gateways

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html

Upvotes: 5

Related Questions