aws / aws/aws-cdk

(aws-cdk-lib/aws_ec2): (Can't create Internet Gateway without public subnets)

Open
#34,069 2 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-ec2 bug p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

I specified "create InternetGateway" prop true and "subnetConfiguration" as "PRIVATE_ISOLATED". But It doesn't make Internet Gateway. I Use Internet Gateway only for Cloud front VPC origin.

```
new _Vpc(this, 'Vpc', {
ipAddresses: IpAddresses.cidr('10.0.0.0/16'),
availabilityZones: ["ap-northeast-1a", "ap-northeast-1c"],
ipProtocol: IpProtocol.IPV4_ONLY,
createInternetGateway: true,
subnetConfiguration: [
{
cidrMask: 24,
name: 'SubnetA',
subnetType: SubnetType.PRIVATE_ISOLATED
},
{
cidrMask: 24,
name: 'SubnetB',
subnetType: SubnetType.PRIVATE_ISOLATED
},
{
cidrMask: 24,
name: 'SubnetC',
subnetType: SubnetType.PRIVATE_ISOLATED
},
{
cidrMask: 24,
name: 'SubnetD',
subnetType: SubnetType.PRIVATE_ISOLATED
},
]
});
```

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

It makes Internet Gateway and Private Subnets

### Current Behavior

It doesn't makes Internet Gateway

### Reproduction Steps

```
new _Vpc(this, 'Vpc', {
ipAddresses: IpAddresses.cidr('10.0.0.0/16'),
availabilityZones: ["ap-northeast-1a", "ap-northeast-1c"],
ipProtocol: IpProtocol.IPV4_ONLY,
createInternetGateway: true,
subnetConfiguration: [
{
cidrMask: 24,
name: 'SubnetA',
subnetType: SubnetType.PRIVATE_ISOLATED
},
{
cidrMask: 24,
name: 'SubnetB',
subnetType: SubnetType.PRIVATE_ISOLATED
},
{
cidrMask: 24,
name: 'SubnetC',
subnetType: SubnetType.PRIVATE_ISOLATED
},
{
cidrMask: 24,
name: 'SubnetD',
subnetType: SubnetType.PRIVATE_ISOLATED
},
]
});
```

### Possible Solution

Remove the "allowOutbound" condition from the if statement in the process of creating an "Internet Gateway". However, I think it will have a big impact.

/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts line 1614:1629
```
const createInternetGateway = props.createInternetGateway ?? true;
const allowOutbound = this.subnetConfiguration.filter(
subnet => (subnet.subnetType !== SubnetType.PRIVATE_ISOLATED && subnet.subnetType !== SubnetType.ISOLATED && !subnet.reserved)).length > 0;

// Create an Internet Gateway and attach it if necessary
if (allowOutbound && createInternetGateway) {
const igw = new CfnInternetGateway(this, 'IGW', {
});

this.internetGatewayId = igw.ref;

this._internetConnectivityEstablished.add(igw);
const att = new CfnVPCGatewayAttachment(this, 'VPCGW', {
internetGatewayId: igw.ref,
vpcId: this.resource.ref,
});
```

### Additional Information/Context

_No response_

### CDK CLI Version

2.1006.0

### Framework Version

_No response_

### Node.js Version

v23.10.0

### OS

Mac OS

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at packages/aws-cdk-lib/aws-ec2/lib/vpc.ts lines 1614-1629 and reproduce the supplied TypeScript VPC configuration with CDK synthesis. Trace how createInternetGateway and PRIVATE_ISOLATED subnet settings affect resource creation; done means the synthesized VPC includes an Internet Gateway attachment alongside the isolated subnets when requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.