@friggframework/devtools 2.0.0--canary.710.9045bbc.0 → 2.0.0--canary.711.f8b6445.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -30
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
- package/frigg-cli/__tests__/unit/commands/install.test.js +0 -7
- package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/index.test.js +158 -0
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
- package/infrastructure/domains/networking/vpc-builder.js +8 -18
- package/infrastructure/domains/networking/vpc-builder.test.js +13 -32
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
- package/infrastructure/infrastructure-composer.test.js +794 -268
- package/infrastructure/integration.test.js +381 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
- package/infrastructure/scripts/build-time-discovery.test.js +3 -18
- package/package.json +7 -7
|
@@ -5,17 +5,6 @@
|
|
|
5
5
|
* valid, consistent CloudFormation templates.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// Never touch AWS or the real Prisma layer from a unit test: discovery returns
|
|
9
|
-
// nothing (a fresh account), and the layer build (npm install into
|
|
10
|
-
// layers/prisma) is stubbed out.
|
|
11
|
-
jest.mock('../domains/shared/resource-discovery', () => ({
|
|
12
|
-
...jest.requireActual('../domains/shared/resource-discovery'),
|
|
13
|
-
gatherDiscoveredResources: jest.fn().mockResolvedValue({}),
|
|
14
|
-
}));
|
|
15
|
-
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
16
|
-
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
8
|
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
20
9
|
|
|
21
10
|
describe('CloudFormation Template Generation', () => {
|
|
@@ -97,16 +86,11 @@ describe('CloudFormation Template Generation', () => {
|
|
|
97
86
|
|
|
98
87
|
// Framework-generated resources (created by Serverless Framework, not our builders)
|
|
99
88
|
const frameworkResources = ['HttpApi', 'HttpApiLogGroup'];
|
|
100
|
-
// Serverless names each function's resource `<Name>LambdaFunction`
|
|
101
|
-
// (e.g. dbMigrationWorker -> DbMigrationWorkerLambdaFunction).
|
|
102
|
-
const functionResources = Object.keys(result.functions || {}).map(
|
|
103
|
-
(name) => `${name.charAt(0).toUpperCase()}${name.slice(1)}LambdaFunction`
|
|
104
|
-
);
|
|
105
89
|
|
|
106
|
-
// Verify all Refs point to existing resources, layers,
|
|
90
|
+
// Verify all Refs point to existing resources, layers, or framework resources
|
|
107
91
|
refs.forEach(ref => {
|
|
108
92
|
if (!frameworkResources.includes(ref)) {
|
|
109
|
-
expect(
|
|
93
|
+
expect(allIds).toContain(ref);
|
|
110
94
|
}
|
|
111
95
|
});
|
|
112
96
|
});
|
|
@@ -139,9 +123,7 @@ describe('CloudFormation Template Generation', () => {
|
|
|
139
123
|
integrations: [
|
|
140
124
|
{ Definition: { name: 'slack' } }
|
|
141
125
|
],
|
|
142
|
-
|
|
143
|
-
// created explicitly; `auto` with no VPC found is a hard error.
|
|
144
|
-
vpc: { enable: true, management: 'create-new' },
|
|
126
|
+
vpc: { enable: true },
|
|
145
127
|
encryption: { fieldLevelEncryptionMethod: 'kms' }
|
|
146
128
|
};
|
|
147
129
|
|
|
@@ -269,9 +251,7 @@ describe('CloudFormation Template Generation', () => {
|
|
|
269
251
|
it('should create VPC resources when enabled', async () => {
|
|
270
252
|
const appDefinition = {
|
|
271
253
|
name: 'test-app',
|
|
272
|
-
|
|
273
|
-
// created explicitly; `auto` with no VPC found is a hard error.
|
|
274
|
-
vpc: { enable: true, management: 'create-new' },
|
|
254
|
+
vpc: { enable: true },
|
|
275
255
|
integrations: []
|
|
276
256
|
};
|
|
277
257
|
|
|
@@ -284,9 +264,7 @@ describe('CloudFormation Template Generation', () => {
|
|
|
284
264
|
it('should create subnets in VPC', async () => {
|
|
285
265
|
const appDefinition = {
|
|
286
266
|
name: 'test-app',
|
|
287
|
-
|
|
288
|
-
// created explicitly; `auto` with no VPC found is a hard error.
|
|
289
|
-
vpc: { enable: true, management: 'create-new' },
|
|
267
|
+
vpc: { enable: true },
|
|
290
268
|
integrations: []
|
|
291
269
|
};
|
|
292
270
|
|
|
@@ -299,9 +277,7 @@ describe('CloudFormation Template Generation', () => {
|
|
|
299
277
|
it('should create security group in VPC', async () => {
|
|
300
278
|
const appDefinition = {
|
|
301
279
|
name: 'test-app',
|
|
302
|
-
|
|
303
|
-
// created explicitly; `auto` with no VPC found is a hard error.
|
|
304
|
-
vpc: { enable: true, management: 'create-new' },
|
|
280
|
+
vpc: { enable: true },
|
|
305
281
|
integrations: []
|
|
306
282
|
};
|
|
307
283
|
|
|
@@ -314,9 +290,7 @@ describe('CloudFormation Template Generation', () => {
|
|
|
314
290
|
it('should configure Lambda functions with VPC', async () => {
|
|
315
291
|
const appDefinition = {
|
|
316
292
|
name: 'test-app',
|
|
317
|
-
|
|
318
|
-
// created explicitly; `auto` with no VPC found is a hard error.
|
|
319
|
-
vpc: { enable: true, management: 'create-new' },
|
|
293
|
+
vpc: { enable: true },
|
|
320
294
|
integrations: [
|
|
321
295
|
{ Definition: { name: 'slack' } }
|
|
322
296
|
]
|
|
@@ -453,9 +427,7 @@ describe('CloudFormation Template Generation', () => {
|
|
|
453
427
|
{ Definition: { name: 'slack' } },
|
|
454
428
|
{ Definition: { name: 'hubspot' } }
|
|
455
429
|
],
|
|
456
|
-
|
|
457
|
-
// created explicitly; `auto` with no VPC found is a hard error.
|
|
458
|
-
vpc: { enable: true, management: 'create-new' },
|
|
430
|
+
vpc: { enable: true },
|
|
459
431
|
encryption: { useDefaultKMSForFieldLevelEncryption: true },
|
|
460
432
|
database: {
|
|
461
433
|
type: 'postgresql',
|
|
@@ -84,12 +84,10 @@ describe('MismatchAnalyzer Method Name Bug Fix', () => {
|
|
|
84
84
|
driftStatus: 'MODIFIED',
|
|
85
85
|
propertyDifferences: [
|
|
86
86
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
ActualValue: 'false',
|
|
92
|
-
DifferenceType: 'NOT_EQUAL',
|
|
87
|
+
propertyPath: 'BucketEncryption.Rules[0].BucketKeyEnabled',
|
|
88
|
+
expectedValue: true,
|
|
89
|
+
actualValue: false,
|
|
90
|
+
differenceType: 'NOT_EQUAL',
|
|
93
91
|
},
|
|
94
92
|
],
|
|
95
93
|
});
|
|
@@ -146,12 +144,10 @@ describe('MismatchAnalyzer Method Name Bug Fix', () => {
|
|
|
146
144
|
actualProperties: { BucketEncryption: { enabled: false } },
|
|
147
145
|
propertyDifferences: [
|
|
148
146
|
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
ActualValue: 'false',
|
|
154
|
-
DifferenceType: 'NOT_EQUAL',
|
|
147
|
+
propertyPath: 'BucketEncryption.enabled',
|
|
148
|
+
expectedValue: true,
|
|
149
|
+
actualValue: false,
|
|
150
|
+
differenceType: 'NOT_EQUAL',
|
|
155
151
|
},
|
|
156
152
|
],
|
|
157
153
|
});
|
|
@@ -548,11 +548,7 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
548
548
|
expect(result.unmappedCount).toBe(2);
|
|
549
549
|
});
|
|
550
550
|
|
|
551
|
-
it('should
|
|
552
|
-
// Since 6a0bba7b, importWithLogicalIdMapping() de-duplicates candidates
|
|
553
|
-
// per logical ID and only warns about the candidates it dropped
|
|
554
|
-
// (_checkForMultipleResources(duplicates)). Distinct logical IDs are not
|
|
555
|
-
// duplicates and produce no warning.
|
|
551
|
+
it('should generate warnings for multiple resources of same type', async () => {
|
|
556
552
|
// Arrange
|
|
557
553
|
const stackIdentifier = {
|
|
558
554
|
stackName: 'acme-integrations-dev',
|
|
@@ -592,7 +588,7 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
592
588
|
const buildTemplate = { resources: {} };
|
|
593
589
|
const deployedTemplate = { resources: {} };
|
|
594
590
|
|
|
595
|
-
// Three VPCs
|
|
591
|
+
// Three VPCs mapped
|
|
596
592
|
const mappings = [
|
|
597
593
|
{
|
|
598
594
|
logicalId: 'FriggVPC',
|
|
@@ -602,14 +598,14 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
602
598
|
confidence: 'high',
|
|
603
599
|
},
|
|
604
600
|
{
|
|
605
|
-
logicalId: '
|
|
601
|
+
logicalId: 'FriggVPC2',
|
|
606
602
|
physicalId: 'vpc-456',
|
|
607
603
|
resourceType: 'AWS::EC2::VPC',
|
|
608
604
|
matchMethod: 'contained-resources',
|
|
609
605
|
confidence: 'high',
|
|
610
606
|
},
|
|
611
607
|
{
|
|
612
|
-
logicalId: '
|
|
608
|
+
logicalId: 'FriggVPC3',
|
|
613
609
|
physicalId: 'vpc-789',
|
|
614
610
|
resourceType: 'AWS::EC2::VPC',
|
|
615
611
|
matchMethod: 'tag',
|
|
@@ -632,21 +628,13 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
632
628
|
});
|
|
633
629
|
|
|
634
630
|
// Assert
|
|
635
|
-
// Nothing is referenced by the deployed template, so the first candidate
|
|
636
|
-
// is kept and the other two are reported as duplicates.
|
|
637
631
|
expect(result.success).toBe(true);
|
|
638
|
-
expect(result.mappedCount).toBe(1);
|
|
639
|
-
expect(result.mappings[0].physicalId).toBe('vpc-123');
|
|
640
|
-
expect(result.duplicatesRemoved).toBe(2);
|
|
641
632
|
expect(result.warnings).toHaveLength(1);
|
|
642
633
|
expect(result.warnings[0].type).toBe('MULTIPLE_RESOURCES');
|
|
643
634
|
expect(result.warnings[0].resourceType).toBe('AWS::EC2::VPC');
|
|
644
|
-
expect(result.warnings[0].count).toBe(
|
|
645
|
-
expect(result.warnings[0].message).toContain('Multiple VPCs detected (
|
|
646
|
-
expect(result.warnings[0].resources.
|
|
647
|
-
'vpc-456',
|
|
648
|
-
'vpc-789',
|
|
649
|
-
]);
|
|
635
|
+
expect(result.warnings[0].count).toBe(3);
|
|
636
|
+
expect(result.warnings[0].message).toContain('Multiple VPCs detected (3)');
|
|
637
|
+
expect(result.warnings[0].resources).toHaveLength(3);
|
|
650
638
|
});
|
|
651
639
|
|
|
652
640
|
it('should include build and deployed template paths in result', async () => {
|
package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js
CHANGED
|
@@ -133,12 +133,10 @@ describe('RunHealthCheckUseCase', () => {
|
|
|
133
133
|
driftStatus: 'MODIFIED',
|
|
134
134
|
propertyDifferences: [
|
|
135
135
|
{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
ActualValue: 'false',
|
|
141
|
-
DifferenceType: 'NOT_EQUAL',
|
|
136
|
+
propertyPath: 'Properties.EnableDnsSupport',
|
|
137
|
+
expectedValue: true,
|
|
138
|
+
actualValue: false,
|
|
139
|
+
differenceType: 'NOT_EQUAL',
|
|
142
140
|
},
|
|
143
141
|
],
|
|
144
142
|
});
|
|
@@ -310,12 +308,10 @@ describe('RunHealthCheckUseCase', () => {
|
|
|
310
308
|
driftStatus: 'MODIFIED',
|
|
311
309
|
propertyDifferences: [
|
|
312
310
|
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
ActualValue: 'false',
|
|
318
|
-
DifferenceType: 'NOT_EQUAL',
|
|
311
|
+
propertyPath: 'Properties.EnableDnsSupport',
|
|
312
|
+
expectedValue: true,
|
|
313
|
+
actualValue: false,
|
|
314
|
+
differenceType: 'NOT_EQUAL',
|
|
319
315
|
},
|
|
320
316
|
],
|
|
321
317
|
});
|
package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js
CHANGED
|
@@ -412,23 +412,24 @@ describe('ImportProgressMonitor', () => {
|
|
|
412
412
|
|
|
413
413
|
mockCloudFormationRepository.getStackStatus.mockResolvedValue('IMPORT_IN_PROGRESS');
|
|
414
414
|
|
|
415
|
-
// Act & Assert -
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
415
|
+
// Act & Assert - wrap in expect().rejects to properly handle async rejection
|
|
416
|
+
await expect(
|
|
417
|
+
(async () => {
|
|
418
|
+
const resultPromise = monitor.monitorImport({
|
|
419
|
+
stackIdentifier,
|
|
420
|
+
resourceLogicalIds,
|
|
421
|
+
onProgress,
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// Advance timers beyond 5 minutes (300,000ms) in chunks
|
|
425
|
+
// Simulate 151 polls (302 seconds = 302,000ms) to exceed timeout
|
|
426
|
+
for (let i = 0; i < 151; i++) {
|
|
427
|
+
await jest.advanceTimersByTimeAsync(2000);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return await resultPromise;
|
|
431
|
+
})()
|
|
432
|
+
).rejects.toThrow('Import operation timed out');
|
|
432
433
|
});
|
|
433
434
|
|
|
434
435
|
it('should filter events by resourceLogicalIds', async () => {
|
package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js
CHANGED
|
@@ -302,14 +302,9 @@ describe('UpdateProgressMonitor', () => {
|
|
|
302
302
|
onProgress: onProgressCallback,
|
|
303
303
|
});
|
|
304
304
|
|
|
305
|
-
// Attach the rejection handler before advancing the fake clock: the
|
|
306
|
-
// monitor rejects while the timers run, and an unobserved rejection
|
|
307
|
-
// fails the test under Jest 30.
|
|
308
|
-
const assertion = expect(monitorPromise).rejects.toThrow('Update operation failed and rolled back');
|
|
309
|
-
|
|
310
305
|
await jest.advanceTimersByTimeAsync(2000);
|
|
311
306
|
|
|
312
|
-
await
|
|
307
|
+
await expect(monitorPromise).rejects.toThrow('Update operation failed and rolled back');
|
|
313
308
|
});
|
|
314
309
|
});
|
|
315
310
|
|
|
@@ -339,15 +334,10 @@ describe('UpdateProgressMonitor', () => {
|
|
|
339
334
|
onProgress: onProgressCallback,
|
|
340
335
|
});
|
|
341
336
|
|
|
342
|
-
// Attach the rejection handler before advancing the fake clock: the
|
|
343
|
-
// monitor rejects while the timers run, and an unobserved rejection
|
|
344
|
-
// fails the test under Jest 30.
|
|
345
|
-
const assertion = expect(monitorPromise).rejects.toThrow('Update operation timed out');
|
|
346
|
-
|
|
347
337
|
// Advance past 5 minute timeout (300000ms)
|
|
348
338
|
await jest.advanceTimersByTimeAsync(300000 + 2000);
|
|
349
339
|
|
|
350
|
-
await
|
|
340
|
+
await expect(monitorPromise).rejects.toThrow('Update operation timed out');
|
|
351
341
|
});
|
|
352
342
|
});
|
|
353
343
|
|
|
@@ -82,14 +82,7 @@ jest.mock('@aws-sdk/client-kms', () => ({
|
|
|
82
82
|
ListAliasesCommand: jest.fn(),
|
|
83
83
|
}));
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
// AWSResourceDetector has no findOrphanedResourcesWithRelationships() or
|
|
87
|
-
// _extractReferencedResourceIds(); the design is in
|
|
88
|
-
// domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md. (A template-based variant of
|
|
89
|
-
// the reference analysis lives in RepairViaImportUseCase._extractReferencedIdsFromTemplate.)
|
|
90
|
-
// Un-skip when the relationship analysis is implemented.
|
|
91
|
-
// Tracked in https://github.com/friggframework/frigg/issues/709
|
|
92
|
-
describe.skip('Orphan Detection with Relationship Analysis (TDD)', () => {
|
|
85
|
+
describe('Orphan Detection with Relationship Analysis (TDD)', () => {
|
|
93
86
|
let detector;
|
|
94
87
|
let mockEC2Send;
|
|
95
88
|
let mockRDSSend;
|
package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js
CHANGED
|
@@ -447,9 +447,7 @@ describe('AWSPropertyReconciler', () => {
|
|
|
447
447
|
);
|
|
448
448
|
|
|
449
449
|
expect(strategy.supportsTemplateUpdate).toBe(true);
|
|
450
|
-
|
|
451
|
-
// (UpdateFunctionConfiguration) since 6a0bba7b; template is still preferred.
|
|
452
|
-
expect(strategy.supportsResourceUpdate).toBe(true);
|
|
450
|
+
expect(strategy.supportsResourceUpdate).toBe(false);
|
|
453
451
|
expect(strategy.recommendedMode).toBe('template');
|
|
454
452
|
expect(strategy.limitations).toContain(
|
|
455
453
|
'VpcConfig changes may take several minutes to propagate'
|
|
@@ -661,7 +659,7 @@ describe('AWSPropertyReconciler', () => {
|
|
|
661
659
|
|
|
662
660
|
expect(strategy).toEqual({
|
|
663
661
|
supportsTemplateUpdate: true,
|
|
664
|
-
supportsResourceUpdate:
|
|
662
|
+
supportsResourceUpdate: false,
|
|
665
663
|
recommendedMode: 'template',
|
|
666
664
|
limitations: expect.arrayContaining([
|
|
667
665
|
'VpcConfig changes may take several minutes to propagate',
|
|
@@ -441,16 +441,6 @@ describe('AWSResourceDetector', () => {
|
|
|
441
441
|
describe('findOrphanedResources', () => {
|
|
442
442
|
const StackIdentifier = require('../../domain/value-objects/stack-identifier');
|
|
443
443
|
|
|
444
|
-
beforeEach(() => {
|
|
445
|
-
// findOrphanedResources() scans every supported resource type
|
|
446
|
-
// (EC2, RDS and KMS), not just the types in the stack, so every
|
|
447
|
-
// client needs an (empty) response; each test overrides the one
|
|
448
|
-
// service it is about.
|
|
449
|
-
mockEC2Send.mockResolvedValue({});
|
|
450
|
-
mockRDSSend.mockResolvedValue({});
|
|
451
|
-
mockKMSSend.mockResolvedValue({});
|
|
452
|
-
});
|
|
453
|
-
|
|
454
444
|
it('should find orphaned RDS DBCluster with frigg:stack tag', async () => {
|
|
455
445
|
const stackIdentifier = new StackIdentifier({
|
|
456
446
|
stackName: 'my-app-prod',
|
|
@@ -439,14 +439,8 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
439
439
|
translated.vpc.ownership.subnets = 'external';
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
// Legacy options that warnIgnoredOptions() reports as ignored under
|
|
443
|
-
// managementMode='managed' must really be ignored: applying them would
|
|
444
|
-
// undo the ownership chosen above (e.g. vpc.management='discover' turning
|
|
445
|
-
// managed+isolated's ownership.vpc='stack' back into 'auto').
|
|
446
|
-
const honorLegacyModes = globalMode !== 'managed';
|
|
447
|
-
|
|
448
442
|
// Handle legacy vpc.management modes
|
|
449
|
-
const vpcManagement =
|
|
443
|
+
const vpcManagement = appDefinition.vpc?.management;
|
|
450
444
|
if (vpcManagement === 'create-new') {
|
|
451
445
|
translated.vpc.ownership.vpc = 'stack';
|
|
452
446
|
translated.vpc.ownership.securityGroup = 'stack';
|
|
@@ -472,7 +466,7 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
472
466
|
}
|
|
473
467
|
|
|
474
468
|
// Handle legacy shareAcrossStages
|
|
475
|
-
if (
|
|
469
|
+
if (appDefinition.vpc?.shareAcrossStages !== undefined) {
|
|
476
470
|
if (appDefinition.vpc.shareAcrossStages) {
|
|
477
471
|
// Shared VPC - discover and reuse
|
|
478
472
|
translated.vpc.ownership.vpc = 'auto';
|
|
@@ -487,7 +481,7 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
487
481
|
}
|
|
488
482
|
|
|
489
483
|
// Handle legacy NAT Gateway management
|
|
490
|
-
if (
|
|
484
|
+
if (appDefinition.vpc?.natGateway?.management === 'createAndManage') {
|
|
491
485
|
// Use 'auto' to allow discovering and reusing properly placed external NAT Gateways
|
|
492
486
|
// The resolver will check if there's a good external NAT Gateway and reuse it,
|
|
493
487
|
// or create a new one if needed (or if the existing one is misplaced)
|
|
@@ -499,10 +493,9 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
499
493
|
}
|
|
500
494
|
|
|
501
495
|
// Handle legacy subnet management
|
|
502
|
-
|
|
503
|
-
if (subnetManagement === 'create') {
|
|
496
|
+
if (appDefinition.vpc?.subnets?.management === 'create') {
|
|
504
497
|
translated.vpc.ownership.subnets = 'stack';
|
|
505
|
-
} else if (
|
|
498
|
+
} else if (appDefinition.vpc?.subnets?.management === 'use-existing' && appDefinition.vpc.subnets.ids) {
|
|
506
499
|
translated.vpc.ownership.subnets = 'external';
|
|
507
500
|
translated.vpc.external.subnetIds = appDefinition.vpc.subnets.ids;
|
|
508
501
|
}
|
|
@@ -698,11 +691,8 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
698
691
|
result.vpcConfig.securityGroupIds = [{ Ref: 'FriggLambdaSecurityGroup' }];
|
|
699
692
|
console.log(' ✅ Security Group added to template');
|
|
700
693
|
} else if (decision.ownership === ResourceOwnership.EXTERNAL) {
|
|
701
|
-
// Use external security group IDs
|
|
702
|
-
|
|
703
|
-
const sgIds = decision.physicalIds?.length
|
|
704
|
-
? decision.physicalIds
|
|
705
|
-
: Array.isArray(decision.physicalId) ? decision.physicalId : [decision.physicalId];
|
|
694
|
+
// Use external security group IDs
|
|
695
|
+
const sgIds = Array.isArray(decision.physicalId) ? decision.physicalId : [decision.physicalId];
|
|
706
696
|
result.vpcConfig.securityGroupIds = sgIds;
|
|
707
697
|
console.log(` ✓ Using external security group(s): ${sgIds.join(', ')}`);
|
|
708
698
|
}
|
|
@@ -1185,7 +1175,7 @@ class VpcBuilder extends InfrastructureBuilder {
|
|
|
1185
1175
|
const vpcId = result.vpcId;
|
|
1186
1176
|
|
|
1187
1177
|
// Determine logical IDs based on what exists in stack for backwards compatibility
|
|
1188
|
-
// CRITICAL:
|
|
1178
|
+
// CRITICAL: Frontify production uses OLD naming (VPCEndpointS3, not FriggS3VPCEndpoint)
|
|
1189
1179
|
const existingLogicalIds = discoveredResources?.existingLogicalIds || [];
|
|
1190
1180
|
|
|
1191
1181
|
|
|
@@ -293,10 +293,10 @@ describe('VpcBuilder', () => {
|
|
|
293
293
|
]);
|
|
294
294
|
expect(result.resources.FriggPrivateSubnet1).toBeDefined();
|
|
295
295
|
expect(result.resources.FriggPrivateSubnet2).toBeDefined();
|
|
296
|
-
// In discover mode
|
|
297
|
-
|
|
298
|
-
expect(result.
|
|
299
|
-
expect(result.resources.FriggLambdaSecurityGroup).
|
|
296
|
+
// In discover mode, we create FriggLambdaSecurityGroup in the discovered VPC
|
|
297
|
+
expect(result.vpcConfig.securityGroupIds).toEqual([{ Ref: 'FriggLambdaSecurityGroup' }]);
|
|
298
|
+
expect(result.resources.FriggLambdaSecurityGroup).toBeDefined();
|
|
299
|
+
expect(result.resources.FriggLambdaSecurityGroup.Properties.VpcId).toBe('vpc-discovered');
|
|
300
300
|
});
|
|
301
301
|
|
|
302
302
|
it('should allow sharing discovered subnets when explicitly configured', async () => {
|
|
@@ -330,8 +330,6 @@ describe('VpcBuilder', () => {
|
|
|
330
330
|
management: 'discover',
|
|
331
331
|
selfHeal: true,
|
|
332
332
|
},
|
|
333
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
334
|
-
database: { dynamodb: { enable: true } },
|
|
335
333
|
};
|
|
336
334
|
|
|
337
335
|
const discoveredResources = {
|
|
@@ -464,8 +462,6 @@ describe('VpcBuilder', () => {
|
|
|
464
462
|
const appDefinition = {
|
|
465
463
|
vpc: { enable: true },
|
|
466
464
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
467
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
468
|
-
database: { dynamodb: { enable: true } },
|
|
469
465
|
};
|
|
470
466
|
|
|
471
467
|
// Structured discovery from CloudFormation
|
|
@@ -526,8 +522,6 @@ describe('VpcBuilder', () => {
|
|
|
526
522
|
const appDefinition = {
|
|
527
523
|
vpc: { enable: true, enableVPCEndpoints: true, selfHeal: true },
|
|
528
524
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
529
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
530
|
-
database: { dynamodb: { enable: true } },
|
|
531
525
|
};
|
|
532
526
|
const discoveredResources = {
|
|
533
527
|
defaultVpcId: 'vpc-123',
|
|
@@ -821,9 +815,7 @@ describe('VpcBuilder', () => {
|
|
|
821
815
|
};
|
|
822
816
|
|
|
823
817
|
const discoveredResources = {
|
|
824
|
-
|
|
825
|
-
// the resolver refuses to create one implicitly (37a354e8).
|
|
826
|
-
defaultVpcId: 'vpc-123',
|
|
818
|
+
vpcId: 'vpc-123',
|
|
827
819
|
privateSubnetId1: 'subnet-existing-1',
|
|
828
820
|
privateSubnetId2: 'subnet-existing-2',
|
|
829
821
|
natGatewayId: 'nat-existing',
|
|
@@ -833,15 +825,9 @@ describe('VpcBuilder', () => {
|
|
|
833
825
|
|
|
834
826
|
const result = await vpcBuilder.build(appDefinition, discoveredResources);
|
|
835
827
|
|
|
836
|
-
// The builder always emits the new association logical IDs, even when
|
|
837
|
-
// the stack still has the old FriggSubnetNRouteAssociation ones, so
|
|
838
|
-
// CloudFormation replaces drifted associations (see createNatGatewayRouting).
|
|
839
|
-
expect(result.resources.FriggSubnet1RouteAssociation).toBeUndefined();
|
|
840
|
-
expect(result.resources.FriggSubnet2RouteAssociation).toBeUndefined();
|
|
841
|
-
|
|
842
828
|
// Verify associations have UpdateReplacePolicy to force recreation
|
|
843
|
-
expect(result.resources.
|
|
844
|
-
expect(result.resources.
|
|
829
|
+
expect(result.resources.FriggSubnet1RouteAssociation.UpdateReplacePolicy).toBe('Delete');
|
|
830
|
+
expect(result.resources.FriggSubnet2RouteAssociation.UpdateReplacePolicy).toBe('Delete');
|
|
845
831
|
|
|
846
832
|
// This forces CloudFormation to delete old associations and create new ones
|
|
847
833
|
// instead of trying to update them in-place (which doesn't work)
|
|
@@ -1536,7 +1522,7 @@ describe('VpcBuilder', () => {
|
|
|
1536
1522
|
});
|
|
1537
1523
|
|
|
1538
1524
|
it('should use OLD logical IDs for backwards compatibility (FriggNATRoute, VPCEndpointS3 pattern)', async () => {
|
|
1539
|
-
// CRITICAL TEST:
|
|
1525
|
+
// CRITICAL TEST: Real Frontify production stack uses OLD naming convention
|
|
1540
1526
|
// Stack currently has: FriggNATRoute, VPCEndpointS3, VPCEndpointDynamoDB
|
|
1541
1527
|
// We MUST use these same logical IDs to avoid AlreadyExists errors
|
|
1542
1528
|
const appDefinition = {
|
|
@@ -1555,7 +1541,7 @@ describe('VpcBuilder', () => {
|
|
|
1555
1541
|
}
|
|
1556
1542
|
};
|
|
1557
1543
|
|
|
1558
|
-
// Discovery results matching
|
|
1544
|
+
// Discovery results matching ACTUAL Frontify production stack
|
|
1559
1545
|
const discoveredResources = {
|
|
1560
1546
|
fromCloudFormationStack: true,
|
|
1561
1547
|
stackName: 'create-frigg-app-production',
|
|
@@ -1603,13 +1589,10 @@ describe('VpcBuilder', () => {
|
|
|
1603
1589
|
expect(result.resources.FriggNATRoute.Type).toBe('AWS::EC2::Route');
|
|
1604
1590
|
expect(result.resources.FriggPrivateRoute).toBeUndefined(); // Should NOT create new ID
|
|
1605
1591
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
expect(result.resources.
|
|
1610
|
-
expect(result.resources.FriggSubnet2RouteAssociation).toBeUndefined();
|
|
1611
|
-
expect(result.resources.FriggPrivateSubnet1RouteTableAssociation).toBeDefined();
|
|
1612
|
-
expect(result.resources.FriggPrivateSubnet2RouteTableAssociation).toBeDefined();
|
|
1592
|
+
expect(result.resources.FriggSubnet1RouteAssociation).toBeDefined();
|
|
1593
|
+
expect(result.resources.FriggSubnet2RouteAssociation).toBeDefined();
|
|
1594
|
+
expect(result.resources.FriggPrivateSubnet1RouteTableAssociation).toBeUndefined();
|
|
1595
|
+
expect(result.resources.FriggPrivateSubnet2RouteTableAssociation).toBeUndefined();
|
|
1613
1596
|
|
|
1614
1597
|
expect(result.resources.VPCEndpointS3).toBeDefined();
|
|
1615
1598
|
expect(result.resources.VPCEndpointS3.Type).toBe('AWS::EC2::VPCEndpoint');
|
|
@@ -1831,8 +1814,6 @@ describe('VpcBuilder', () => {
|
|
|
1831
1814
|
const appDefinition = {
|
|
1832
1815
|
vpc: { enable: true },
|
|
1833
1816
|
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
1834
|
-
// The DynamoDB gateway endpoint is opt-in since 37a354e8
|
|
1835
|
-
database: { dynamodb: { enable: true } },
|
|
1836
1817
|
};
|
|
1837
1818
|
|
|
1838
1819
|
const discoveredResources = {
|