@@ -282,6 +282,11 @@ abstract class VpcBase extends Resource implements IVpc {
282
282
*/
283
283
protected readonly natDependencies = new Array < IConstruct > ( ) ;
284
284
285
+ /**
286
+ * If this is set to true, don't error out on trying to select subnets
287
+ */
288
+ protected incompleteSubnetDefinition : boolean = false ;
289
+
285
290
/**
286
291
* Returns IDs of selected subnets
287
292
*/
@@ -347,7 +352,7 @@ abstract class VpcBase extends Resource implements IVpc {
347
352
const allSubnets = [ ...this . publicSubnets , ...this . privateSubnets , ...this . isolatedSubnets ] ;
348
353
const subnets = allSubnets . filter ( s => subnetGroupNameFromConstructId ( s ) === groupName ) ;
349
354
350
- if ( subnets . length === 0 ) {
355
+ if ( subnets . length === 0 && ! this . incompleteSubnetDefinition ) {
351
356
const names = Array . from ( new Set ( allSubnets . map ( subnetGroupNameFromConstructId ) ) ) ;
352
357
throw new Error ( `There are no subnet groups with name '${ groupName } ' in this VPC. Available names: ${ names } ` ) ;
353
358
}
@@ -369,7 +374,10 @@ abstract class VpcBase extends Resource implements IVpc {
369
374
subnets = subnets . filter ( s => subnetGroupNameFromConstructId ( s ) === subnetGroupNameFromConstructId ( subnets [ 0 ] ) ) ;
370
375
}
371
376
372
- if ( subnets . length === 0 ) {
377
+ // Force merge conflict here with https://github.com/aws/aws-cdk/pull/4089
378
+ // see ImportedVpc
379
+
380
+ if ( subnets . length === 0 && ! this . incompleteSubnetDefinition ) {
373
381
const availableTypes = Object . entries ( allSubnets ) . filter ( ( [ _ , subs ] ) => subs . length > 0 ) . map ( ( [ typeName , _ ] ) => typeName ) ;
374
382
throw new Error ( `There are no '${ subnetType } ' subnet groups in this VPC. Available types: ${ availableTypes } ` ) ;
375
383
}
@@ -759,7 +767,7 @@ export class Vpc extends VpcBase {
759
767
* Import an exported VPC
760
768
*/
761
769
public static fromVpcAttributes ( scope : Construct , id : string , attrs : VpcAttributes ) : IVpc {
762
- return new ImportedVpc ( scope , id , attrs ) ;
770
+ return new ImportedVpc ( scope , id , attrs , false ) ;
763
771
}
764
772
765
773
/**
@@ -796,10 +804,10 @@ export class Vpc extends VpcBase {
796
804
const attributes = ContextProvider . getValue ( scope , {
797
805
provider : cxapi . VPC_PROVIDER ,
798
806
props : { filter } as cxapi . VpcContextQuery ,
799
- dummyValue : DUMMY_VPC_PROPS
807
+ dummyValue : undefined
800
808
} ) ;
801
809
802
- return this . fromVpcAttributes ( scope , id , attributes ) ;
810
+ return new ImportedVpc ( scope , id , attributes || DUMMY_VPC_PROPS , attributes === undefined ) ;
803
811
804
812
/**
805
813
* Prefixes all keys in the argument with `tag:`.`
@@ -1418,12 +1426,13 @@ class ImportedVpc extends VpcBase {
1418
1426
public readonly vpnGatewayId ?: string ;
1419
1427
public readonly internetConnectivityEstablished : IDependable = new ConcreteDependable ( ) ;
1420
1428
1421
- constructor ( scope : Construct , id : string , props : VpcAttributes ) {
1429
+ constructor ( scope : Construct , id : string , props : VpcAttributes , isIncomplete : boolean ) {
1422
1430
super ( scope , id ) ;
1423
1431
1424
1432
this . vpcId = props . vpcId ;
1425
1433
this . availabilityZones = props . availabilityZones ;
1426
1434
this . vpnGatewayId = props . vpnGatewayId ;
1435
+ this . incompleteSubnetDefinition = isIncomplete ;
1427
1436
1428
1437
// tslint:disable:max-line-length
1429
1438
const pub = new ImportSubnetGroup ( props . publicSubnetIds , props . publicSubnetNames , props . publicSubnetRouteTableIds , SubnetType . PUBLIC , this . availabilityZones , 'publicSubnetIds' , 'publicSubnetNames' , 'publicSubnetRouteTableIds' ) ;
0 commit comments