aws / aws/aws-cdk

CfnResolverEndpoint L2 for VPC + TGW subnets

Open
#20,012 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-ec2 effort/medium feature-request feature/new-construct p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

This is the current mixed L1/L2 approach, I think that the subnets mappings for CfnResolverEndpoint and CfnResolverRule and use-case would be useful for L2 so sharing the code.

```ts
export class PipelineVpcStack extends Stack {
public readonly vpc: Vpc;

constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

// create private VPC for communication with internal infra
this.vpc = new Vpc(this, 'Vpc', {
cidr: CIDR,
vpnGateway: false,
subnetConfiguration: [{ cidrMask: 28, name: 'Isolated', subnetType: SubnetType.PRIVATE_ISOLATED }],
});

// allow communication with AWS SSM
new InterfaceVpcEndpoint(this, 'ssm-interface', {
vpc: this.vpc,
service: {
name: `com.amazonaws.${this.region}.ssm`,
port: 443,
},
});

new CfnTransitGatewayAttachment(this, 'TransitGatewayAttachment', {
transitGatewayId: Settings.TGW_ID,
vpcId: this.vpc.vpcId,
subnetIds: this.vpc.isolatedSubnets.map((s) => s.subnetId),
});

this.vpc.isolatedSubnets.forEach(({ routeTable: { routeTableId } }, index) => {
new CfnRoute(this, 'PrivateSubnetPeeringConnectionRoute' + index, {
destinationCidrBlock: '10.0.0.0/8',
routeTableId,
transitGatewayId: Settings.TGW_ID,
});
});

const sg = new SecurityGroup(this, 'SG', {
vpc: this.vpc,
description: 'SG allowing traffic',
allowAllOutbound: true,
});

const resolver = new CfnResolverEndpoint(this, 'OutboundDnsResolverEndpoint', {
direction: 'OUTBOUND',
ipAddresses: this.vpc
.selectSubnets({ subnetType: SubnetType.PRIVATE_ISOLATED })
.subnetIds.map((el) => ({ subnetId: el })),
securityGroupIds: [sg.securityGroupId],
});

const resolverRule = new CfnResolverRule(this, 'ResolverRule', {
name: 'host',
domainName: 'host',
ruleType: 'FORWARD',
resolverEndpointId: resolver.attrResolverEndpointId,
targetIps: CITNET_DNS.map((el) => ({ ip: el })),
});

new CfnResolverRuleAssociation(this, 'ResolverRuleAssociation', {
resolverRuleId: resolverRule.attrResolverRuleId,
vpcId: this.vpc.vpcId,
});
}
}
```

### Use Case

Creating a CDK stack that connects a VPC to a shared TransitGateway and maps subnets to route traffic to TGW.

### Proposed Solution

Make it possible to automatically infer subnets from VPC to CfnResolverEndpoint.

### Other Information

_No response_

### Acknowledgements

- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

1.152.0

### Environment details (OS name and version, etc.)

MacOS

Contributor guide

Open the contributing guide

Research direction

No repository file or test is named. Start by locating the TypeScript L2 and L1 definitions for CfnResolverEndpoint, CfnResolverRule, and Vpc, then compare how subnet mappings are handled; done means supporting automatic subnet inference for a VPC, including the VPC plus Transit Gateway use case described here.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.