> **Experimental**
>
> `@aws-cdk/aws-ec2-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# TransitGateway

Creates a Transit Gateway.

Extends: Construct › Resource › TransitGateway
Implements: IRouteTarget, ITransitGateway, IResource, IEnvironmentAware, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- CloudFormation: [`AWS::EC2::TransitGateway`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-transitgateway.html)
- L1 type: [`CfnTransitGateway`](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnTransitGateway.html)
- Source: [`lib/transit-gateway.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0-alpha.0/packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway.ts#L216)

## Example

```ts
const transitGateway = new TransitGateway(this, 'MyTransitGateway');
const routeTable = transitGateway.addRouteTable('CustomRouteTable');
const myVpc = new VpcV2(this, 'Vpc');
const subnet = new SubnetV2(this, 'Subnet', {
  vpc: myVpc,
  availabilityZone: 'eu-west-2a',
  ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
  subnetType: SubnetType.PUBLIC
});
const attachment = transitGateway.attachVpc('VpcAttachment', {
  vpc: myVpc,
  subnets: [subnet]
});

// Associate an attachment with a route table
routeTable.addAssociation('Association', attachment);

// Enable route propagation for an attachment
routeTable.enablePropagation('Propagation', attachment);
```

## Initializer

```ts
new TransitGateway(scope: Construct, id: string, props?: TransitGatewayProps)
```

## Construct Props

- `amazonSideAsn`: number — A private Autonomous System Number (ASN) for the Amazon side of a BGP session.

  **Default:** undefined, 64512 is assigned by CloudFormation.

  The range is 64512 to 65534 for 16-bit ASNs.

- `autoAcceptSharedAttachments`: boolean — Enable or disable automatic acceptance of cross-account attachment requests.

  **Default:** disable (false)

- `defaultRouteTableAssociation`: boolean — Enable or disable automatic association with the default association route table.

  **Default:** enable (true)

- `defaultRouteTablePropagation`: boolean — Enable or disable automatic propagation of routes to the default propagation route table.

  **Default:** enable (true)

- `description`: string — The description of the transit gateway.

  **Default:** no description

- `dnsSupport`: boolean — Enable or disable DNS support.

  **Default:** enable (true)

  If dnsSupport is enabled on a VPC Attachment, this also needs to be enabled for the feature to work.
  Otherwise the resources will still deploy but the feature will not work.

- `securityGroupReferencingSupport`: boolean — Enable or disable security group referencing support.

  **Default:** disable (false)

  If securityGroupReferencingSupport is enabled on a VPC Attachment, this also needs to be enabled for the feature to work.
  Otherwise the resources will still deploy but the feature will not work.

- `transitGatewayCidrBlocks`: string[] = none — The transit gateway CIDR blocks.

- `transitGatewayName`: string — Physical name of this Transit Gateway.

  **Default:** Assigned by CloudFormation.

## Properties

- `defaultRouteTable`: [ITransitGatewayRouteTable](/cdk/api/v2/docs/@aws-cdk_aws-ec2-alpha.ITransitGatewayRouteTable.html) (required) — The default route table associated with the Transit Gateway.

  This route table is created by the CDK and is used to manage the routes
  for attachments that do not have an explicitly defined route table association.

- `defaultRouteTableAssociation`: boolean (required) — Indicates whether new attachments are automatically associated with the default route table.

  If set to `true`, any VPC or VPN attachment will be automatically associated with
  the default route table unless otherwise specified.

- `defaultRouteTablePropagation`: boolean (required) — Indicates whether route propagation to the default route table is enabled.

  When set to `true`, routes from attachments will be automatically propagated
  to the default route table unless propagation is explicitly disabled.

- `dnsSupport`: boolean (required) — Whether or not DNS support is enabled on the Transit Gateway.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `routerTargetId`: string (required) — The ID of the route target.

- `routerType`: [RouterType](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.RouterType.html) (required) — The type of router used in the route.

- `securityGroupReferencingSupport`: boolean (required) — Whether or not security group referencing support is enabled on the Transit Gateway.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

- `transitGatewayArn`: string (required) — The Amazon Resource Name (ARN) of the Transit Gateway.

  The ARN uniquely identifies the Transit Gateway across AWS and is commonly
  used for permissions and resource tracking.

- `transitGatewayId`: string (required) — The unique identifier of the Transit Gateway.

  This ID is automatically assigned by AWS upon creation of the Transit Gateway
  and is used to reference it in various configurations and operations.

## Methods

- `addRouteTable(id: string): ITransitGatewayRouteTable` — Adds a new route table to the Transit Gateway.

  **Returns:** The created Transit Gateway route table.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `attachVpc(id: string, options: AttachVpcOptions): ITransitGatewayVpcAttachment` — Attaches a VPC to the Transit Gateway.

  **Returns:** The created Transit Gateway VPC attachment.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
