fix(Vpc): use self.natInstances in registerOutputs to fix Vpc.get() with bastion #6347
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Vpc.get()failing withReferenceError: Cannot access 'natInstances' before initializationwhen referencing a VPC created withbastion: trueProblem
When using
sst.aws.Vpc.get()to reference an existing VPC that was created withbastion: true, deployment fails with:Root Cause
In
platform/src/components/aws/vpc.ts, theregisterOutputs()function references the local variablenatInstancesinstead of the class propertyself.natInstances.When using
Vpc.get()(the ref path, lines 370-386),registerOutputs()is called at line 385, but the localconst natInstances = createNatInstances();is only defined at line 401 (after the ref code path returns).In the ref path,
this.natInstancesis properly set fromref.natInstances, but theregisterOutputs()function incorrectly references the local variable instead of the class property.Fix
Change
natInstancestoself.natInstancesin theregisterOutputs()function (line 693).Fixes #6346
This is a regression from #5820