feat: add existing VPC import support + fix Route53 hosted zone lookup#138
feat: add existing VPC import support + fix Route53 hosted zone lookup#138jmino wants to merge 10 commits intoBoise-State-Development:mainfrom
Conversation
Fix to extract the parent domain for the zone lookup. Signed-off-by: Julian Mino <5713710+jmino@users.noreply.github.com>
Allow importing a pre-existing VPC via Vpc.fromVpcAttributes() instead of always creating a new one. When the optional existingVpc config block is present, the stack skips VPC/Subnet/NAT creation and uses the provided VPC ID, subnet IDs, and availability zones. Downstream stacks require zero changes since they consume network resources via SSM.
|
Hi @jmino! Wow, thank you for this PR. This is fantastic. We will take a look on Monday and most likely merge early next week. Have a great weekend! :) |
There was a problem hiding this comment.
Pull request overview
Adds optional “import existing VPC” support to the CDK InfrastructureStack so deployments can target a pre-provisioned VPC (hub-and-spoke/shared VPC topologies), and updates Route53 hosted zone lookup behavior for subdomain-based domainName values.
Changes:
- Introduces
ExistingVpcConfigparsing + validation ininfrastructure/lib/config.tsand switchesInfrastructureStackVPC handling toec2.IVpcwith an import branch. - Updates CI/CD + shell scripts to accept/pass new
CDK_EXISTING_VPC_*inputs; adds fast-check property-based tests for config + stack synthesis behavior. - Adjusts frontend Route53 hosted zone lookup logic to derive a parent zone from subdomains.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/stack-infrastructure/synth.sh | Adds passing existing VPC context to synth command. |
| scripts/stack-infrastructure/deploy.sh | Adds passing existing VPC context to deploy command. |
| scripts/common/load-env.sh | Exports/parses CDK_EXISTING_VPC_* and adds them to built context params. |
| infrastructure/test/infrastructure-stack-property.test.ts | Property tests for imported-VPC synth resource counts + SSM parameters. |
| infrastructure/test/helpers/mock-config.ts | Adds existingVpc default to mock config. |
| infrastructure/test/existing-vpc-config.property.test.ts | Property tests for config precedence/validation/round-trip. |
| infrastructure/package.json | Adds fast-check dev dependency. |
| infrastructure/package-lock.json | Locks fast-check dependency. |
| infrastructure/lib/infrastructure-stack.ts | Imports VPC via fromVpcAttributes when configured; adjusts SSM exports. |
| infrastructure/lib/frontend-stack.ts | Changes hosted zone lookup to use derived parent zone name. |
| infrastructure/lib/config.ts | Adds ExistingVpcConfig, parsing, validation, and CIDR-validation bypass logic. |
| infrastructure/cdk.context.json | Updates cached availability-zone lookup data. |
| .kiro/specs/existing-vpc-support/tasks.md | Implementation plan documentation for the feature. |
| .kiro/specs/existing-vpc-support/requirements.md | Requirements documentation for existing VPC support. |
| .kiro/specs/existing-vpc-support/design.md | Design documentation for existing VPC support. |
| .kiro/specs/existing-vpc-support/.config.kiro | Kiro spec metadata for the new feature. |
| .github/workflows/infrastructure.yml | Adds CDK_EXISTING_VPC_* vars to workflow env. |
| .github/docs/deploy/step-03-github-config.md | Documents new CDK_EXISTING_VPC_* variables. |
| .github/ACTIONS-REFERENCE.md | Documents new CDK_EXISTING_VPC_* variables. |
Files not reviewed (1)
- infrastructure/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
infrastructure/package-lock.json:26
package.jsonpinsfast-checkto4.6.0, butpackage-lock.jsonrecords it as^4.6.0underpackages[""]. This mismatch can causenpm cito fail due to an out-of-sync lockfile. Regenerate the lockfile (or align the spec) so the lock reflects the exact version constraint frompackage.json.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…zone lookup Use config.infrastructureHostedZoneDomain (CDK_HOSTED_ZONE_DOMAIN) for the Route53 fromLookup() call instead of deriving the zone name from config.domainName. Falls back to domainName when the hosted zone config is not set, preserving existing behavior for apex domain deployments.
The frontend workflow was missing CDK_HOSTED_ZONE_DOMAIN in its env sections, causing Route53 hosted zone lookups to fail when domainName differs from the hosted zone domain (e.g., app.example.com vs example.com). - Add CDK_HOSTED_ZONE_DOMAIN to synth-cdk and deploy-infrastructure jobs
CDK_HOSTED_ZONE_DOMAIN is a required variable per documentation, so the fallback to domainName is unnecessary.
FrontendStack requires this variable for Route53 hosted zone lookup when synthesizing all stacks.
1b8f1f4 to
a35d0e7
Compare
Testing: Existing VPC ImportNotes:I ran a manual integration test for the changes in this pull request, here are the results. Environment
ConfigurationAdded "existingVpc": {
"vpcId": "vpc-xxxxx",
"availabilityZones": ["us-east-1a", "us-east-1b"],
"publicSubnetIds": ["subnet-pub1", "subnet-pub2"],
"privateSubnetIds": ["subnet-priv1", "subnet-priv2"],
"vpcCidrBlock": "10.0.0.0/16"
}Deployment Steps
Verification
SummaryThe |
Summary
Add optional existing VPC import support for InfrastructureStack. Organizations with hub-and-spoke network topologies or shared VPCs can now deploy into a pre-existing VPC instead of always creating a new one.
What changed
ExistingVpcConfiginterface,parseExistingVpcConfig(), andvalidateExistingVpcConfig()inconfig.tsthis.vpcfromec2.Vpctoec2.IVpc, addedfromVpcAttributes()branch ininfrastructure-stack.tsCDK_EXISTING_VPC_*env vars toload-env.sh,synth.sh,deploy.sh, andinfrastructure.ymlACTIONS-REFERENCE.mdand deploy guide with new variablesHow it works
When
CDK_EXISTING_VPC_IDis set (via env var or CDK context), the stack imports the VPC viaVpc.fromVpcAttributes()and skips VPC/Subnet/NAT creation. When absent, behavior is identical to today. Downstream stacks require zero changes — they consume network resources via SSM parameters regardless of VPC origin.Testing
Additional fix
app.example.com→example.com). Previously failed whendomainNamewas not the zone apex.