From 5ede2c298bca53d8f5d45ffae5a0396c1d427385 Mon Sep 17 00:00:00 2001 From: andrewpatto Date: Tue, 12 Sep 2023 10:59:28 +1000 Subject: [PATCH] More isolated subnet missing behaviour --- packages/client/infrastructure-client.ts | 28 ++++++++++++++++++++---- packages/stack/infrastructure-stack.ts | 8 +++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/client/infrastructure-client.ts b/packages/client/infrastructure-client.ts index 22bfadd..0f995ba 100644 --- a/packages/client/infrastructure-client.ts +++ b/packages/client/infrastructure-client.ts @@ -100,12 +100,30 @@ export class InfrastructureClient { // try to bring in this private subnets if present try { - vpcAttrs.privateSubnetIds = getStringListLookup( + vpcAttrs.privateSubnetIds = undefined; + vpcAttrs.privateSubnetRouteTableIds = undefined; + + const privateSubs = getStringListLookup( vpcPrivateSubnetIdsParameterName(this.infrastructureStackId), ); - vpcAttrs.privateSubnetRouteTableIds = getStringListLookup( - vpcPrivateSubnetRouteTableIdsParameterName(this.infrastructureStackId), - ); + + // sometimes even if the private subnets parameter does not exist - what comes back is a string + // error message - hence our test here to really really establish we have real subnets + // this handles various "empty" private subs cases + if ( + privateSubs && + privateSubs.length > 0 && + privateSubs[0].includes("subnet-") + ) { + vpcAttrs.privateSubnetIds = privateSubs; + + // the assumption is that if private subnets was set - so was its routing + vpcAttrs.privateSubnetRouteTableIds = getStringListLookup( + vpcPrivateSubnetRouteTableIdsParameterName( + this.infrastructureStackId, + ), + ); + } } catch (e) {} // try to bring in the isolated subnets if present @@ -119,6 +137,7 @@ export class InfrastructureClient { // sometimes even if the isolated subnets parameter does not exist - what comes back is a string // error message - hence our test here to really really establish we have real subnets + // this handles various "empty" private subs cases if ( isolatedSubs && isolatedSubs.length > 0 && @@ -126,6 +145,7 @@ export class InfrastructureClient { ) { vpcAttrs.isolatedSubnetIds = isolatedSubs; + // the assumption is that if isolated subnets was set - so was its routing vpcAttrs.isolatedSubnetRouteTableIds = getStringListLookup( vpcIsolatedSubnetRouteTableIdsParameterName( this.infrastructureStackId, diff --git a/packages/stack/infrastructure-stack.ts b/packages/stack/infrastructure-stack.ts index 391933b..35e1d69 100644 --- a/packages/stack/infrastructure-stack.ts +++ b/packages/stack/infrastructure-stack.ts @@ -112,12 +112,12 @@ export class InfrastructureStack extends Stack { }); } else { // CDK has strange behaviour when looking up "optional" parameters - so instead - // we create a parameter of zero length to indicate that we do not have any + // we create a parameter with a single empty string to indicate that we do not have any // private subnets // our infrastructure client handles the other end of this behaviour new StringListParameter(this, "PrivateSubnetIdsParameter", { parameterName: vpcPrivateSubnetIdsParameterName(id), - stringListValue: [], + stringListValue: [""], }); } @@ -135,12 +135,12 @@ export class InfrastructureStack extends Stack { }); } else { // CDK has strange behaviour when looking up "optional" parameters - so instead - // we create a parameter of zero length to indicate that we do not have any + // we create a parameter with a single empty string to indicate that we do not have any // isolated subnets // our infrastructure client handles the other end of this behaviour new StringListParameter(this, "IsolatedSubnetIdsParameter", { parameterName: vpcIsolatedSubnetIdsParameterName(id), - stringListValue: [], + stringListValue: [""], }); }