Closed MichaelHindley closed 4 years ago
Not all VPC layouts are importable at the moment, only VPC layouts that mirror a VPC the CDK would create itself.
Has been addressed
@rix0rrr i do not understand why this issues is closed? I have one RouteTable and three PrivateSubnets and i am not able to import the RouteTable:
Error: Number of privateSubnetRouteTableIds (1) must be equal to the amount of privateSubnetIds (3).
@MichaelHindley have you solved this issue in someway?
I needed this to be able to create a GatewayVpcEndpointAwsService for S3 and with the imported vpc with fromVpcAttributes i could not import the route tables. I have done the following work around:
// import VPC with other method by id
// create an SSM parameters which store the current VPC ID
new ssm.StringParameter(this, 'VPCID', {
parameterName: `/VpcProvider/VPCID`,
stringValue: String(vpcId)
});
// get vpc id so it can be used in vpc lookup
const vpcIdfromssm = ssm.StringParameter.valueFromLookup(this, '/VpcProvider/VPCID');
// use vpc id get from ssm to import vpc
const importVpc = ec2.Vpc.fromLookup(this, 'import-vpc', {
vpcId: vpcIdfromssm,
});
// create S3 endpoint in imported vpc so that routetables can be edited
const s3Endpoint = importVpc.addGatewayEndpoint('s3Endpoint', {
service: ec2.GatewayVpcEndpointAwsService.S3,
subnets: [importVpc.selectSubnets({subnetType: ec2.SubnetType.PRIVATE})],
});
/**
* List of IDs of route tables for the public subnets.
*
* Must be undefined or have a name for every public subnet group.
*
* @default - Retrieving the route table ID of any public subnet will fail
*/
readonly publicSubnetRouteTableIds?: string[];
I added the route table Id twice. Seemed to work.
publicSubnetIds: [cdk.Fn.importValue('PubSubId1'), cdk.Fn.importValue('PubSubId2')],
publicSubnetRouteTableIds: ['RouteTableForBothPublicSubnetsId', 'RouteTableForBothPublicSubnetsId']
I'm submitting a ...
What is the current behavior? Have a RouteTable associated with 2 public subnets, try to add it to a imported vpc.
Results in
Number of publicSubnetRouteTableIds (x) must be equal to the amount of publicSubnetIds (y)
What is the expected behavior (or behavior of feature suggested)? The error message suggests that there MUST be a 1-to-1 mapping between the number of route tables and the number of public subnets, but this is not the case, screenie from the VPC that is imported that has this configuration:
Please tell us about your environment: